Skip to content

Commit 405c3b5

Browse files
authored
feat(app): to dev updates (#1199)
2 parents 7893ff9 + 740c455 commit 405c3b5

File tree

7 files changed

+134
-14
lines changed

7 files changed

+134
-14
lines changed

src/constants/localStorageKeys.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ export const localStorageKeys = {
44
POCKET_ACCOUNT: 'pocketAccount',
55
},
66
MENU_SHOW: 'menuShow',
7+
settings: {
8+
adviserAudio: 'adviserAudio',
9+
adviserVoice: 'adviserVoice',
10+
},
711
};

src/features/adviser/Adviser/Adviser.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import React, { useEffect, useState, useRef } from 'react';
22
import cx from 'classnames';
3+
import { localStorageKeys } from 'src/constants/localStorageKeys';
34
import styles from './Adviser.module.scss';
45
// import TypeIt from 'typeit-react';
56

7+
const adviserAudioKey = localStorageKeys.settings.adviserAudio;
8+
const adviserVoiceKey = localStorageKeys.settings.adviserVoice;
9+
610
export enum AdviserColors {
711
blue = 'blue',
812
green = 'green',
@@ -46,10 +50,11 @@ function play(text: string) {
4650
const utterThis = new SpeechSynthesisUtterance(cleanText);
4751
utterThis.lang = 'en-US';
4852

49-
// woman voice
50-
utterThis.voice = synth
51-
.getVoices()
52-
.find((voice) => voice.name === 'Google US English');
53+
const voiceLS = localStorage.getItem(adviserVoiceKey);
54+
55+
utterThis.voice =
56+
synth.getVoices().find((voice) => voice.name === voiceLS) ||
57+
synth.getVoices()[0];
5358

5459
synth.speak(utterThis);
5560
}
@@ -84,6 +89,12 @@ function Adviser({
8489
const ref = useRef<HTMLDivElement>(null);
8590

8691
useEffect(() => {
92+
const audioEnabled = localStorage.getItem(adviserAudioKey) === 'true';
93+
94+
if (!audioEnabled) {
95+
return;
96+
}
97+
8798
const t = ref.current?.innerText;
8899

89100
if (!t) {

src/pages/Settings/Audio/Audio.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { Display } from 'src/components';
2+
import DisplayTitle from 'src/components/containerGradient/DisplayTitle/DisplayTitle';
3+
4+
import Switch from 'src/components/Switch/Switch';
5+
import { useState } from 'react';
6+
import { localStorageKeys } from 'src/constants/localStorageKeys';
7+
import useAdviserTexts from 'src/features/adviser/useAdviserTexts';
8+
import VoiceList from './VoiceList';
9+
10+
const adviserAudioKey = localStorageKeys.settings.adviserAudio;
11+
12+
function Audio() {
13+
const [adviserAudio, setAdviserAudio] = useState(
14+
localStorage.getItem(adviserAudioKey) === 'true'
15+
);
16+
17+
const { setAdviser } = useAdviserTexts({
18+
successText: 'audio settings',
19+
});
20+
21+
function handleSwitch(value: boolean) {
22+
setAdviserAudio(value);
23+
localStorage.setItem(adviserAudioKey, value.toString());
24+
25+
setAdviser(
26+
`Adviser audio is turned ${value ? 'on' : 'off'}`,
27+
value ? 'green' : 'red'
28+
);
29+
}
30+
31+
return (
32+
<Display title={<DisplayTitle title="audio" />}>
33+
<div>
34+
<Switch
35+
value={adviserAudio}
36+
onChange={handleSwitch}
37+
label="Adviser audio"
38+
/>
39+
40+
<VoiceList />
41+
</div>
42+
</Display>
43+
);
44+
}
45+
46+
export default Audio;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { useEffect, useState } from 'react';
2+
import { Select } from 'src/components';
3+
import { localStorageKeys } from 'src/constants/localStorageKeys';
4+
import useAdviserTexts from 'src/features/adviser/useAdviserTexts';
5+
6+
const { adviserVoice } = localStorageKeys.settings;
7+
8+
function VoiceList() {
9+
const [voices, setVoices] = useState<SpeechSynthesisVoice[]>([]);
10+
const [voice, setVoice] = useState(localStorage.getItem(adviserVoice));
11+
12+
const { setAdviser } = useAdviserTexts({
13+
successText: 'audio settings',
14+
});
15+
16+
useEffect(() => {
17+
const loadVoices = () => {
18+
const voices = window.speechSynthesis.getVoices();
19+
setVoices(voices);
20+
};
21+
22+
loadVoices();
23+
24+
window.speechSynthesis.onvoiceschanged = loadVoices;
25+
}, []);
26+
27+
return (
28+
<div>
29+
<h1>Available Voices</h1>
30+
<ul>
31+
<Select
32+
width={300}
33+
valueSelect={voice}
34+
onChangeSelect={(value) => {
35+
localStorage.setItem(adviserVoice, value);
36+
setVoice(value);
37+
38+
setAdviser(`selected voice: ${value}`);
39+
}}
40+
options={voices.map((voice) => {
41+
return {
42+
value: voice.name,
43+
text: `${voice.name} (${voice.lang})`,
44+
};
45+
})}
46+
/>
47+
</ul>
48+
</div>
49+
);
50+
}
51+
52+
export default VoiceList;

src/pages/Settings/Layout/SettingsMenu/SettingsMenu.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NavLink } from 'react-router-dom';
22
import cx from 'classnames';
3-
import styles from './SettingsMenu.module.scss';
43
import { Display } from 'src/components';
4+
import styles from './SettingsMenu.module.scss';
55

66
type MenuItem = {
77
text: string;
@@ -41,6 +41,13 @@ const links: Array<MenuItem[]> = [
4141
icon: '📡',
4242
},
4343
],
44+
[
45+
{
46+
text: 'Audio',
47+
link: './audio',
48+
icon: '🔊',
49+
},
50+
],
4451
];
4552

4653
function SettingsMenu() {

src/pages/Settings/Settings.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import IpfsSettings from 'src/features/ipfs/ipfsSettings';
33
import Layout from './Layout/Layout';
44
import Keys from '../Keys/Keys';
55
import Hub from '../Hub/hub';
6+
import Audio from './Audio/Audio';
67

78
function Settings() {
89
return (
910
<Routes>
1011
<Route path="/" element={<Layout />}>
1112
<Route index element={<IpfsSettings />} />
1213
<Route path="keys" element={<Keys />} />
14+
<Route path="audio" element={<Audio />} />
1315

1416
<Route path="/*" element={<Hub />} />
1517
</Route>
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
@import '../../../../layouts/variables.module.scss';
1+
@import '../../../../layouts/variables.module';
22

33
$robotHeaderHeight: 130px;
44

55
.wrapper {
66
display: flex;
77
flex-direction: column;
8-
98
}
109

1110
.content {
@@ -14,18 +13,18 @@ $robotHeaderHeight: 130px;
1413
grid-template-rows: 1fr;
1514
justify-content: center;
1615
margin-right: -2px;
17-
1816
height: 70vh;
19-
max-height: calc(100vh - $reservedTopHeight - $actionBarHeight - $robotHeaderHeight);
17+
max-height: calc(
18+
100vh - $reservedTopHeight - $actionBarHeight - $robotHeaderHeight
19+
);
2020

2121
//Display
22-
2322
> :first-child {
24-
>div {
23+
> div {
2524
height: 100%;
2625
}
2726

28-
>div {
27+
> div > div {
2928
// don't understand this scroll
3029
overflow-x: hidden;
3130
}
@@ -36,5 +35,4 @@ $robotHeaderHeight: 130px;
3635
position: relative;
3736
overflow-x: auto;
3837
}
39-
40-
}
38+
}

0 commit comments

Comments
 (0)