1
1
import {
2
- Box , Button , CircularProgress , CircularProgressLabel , FormControl , FormLabel , Heading , SimpleGrid ,
2
+ Box , Button , CircularProgress , CircularProgressLabel , FormControl , FormLabel , Heading , Input , SimpleGrid ,
3
3
Slider ,
4
4
SliderFilledTrack ,
5
5
SliderMark ,
@@ -16,6 +16,10 @@ import {
16
16
DeviceProvider ,
17
17
useDevice
18
18
} from '@deep-foundation/deepmemo-imports/imports/device' ;
19
+ import {
20
+ VoiceProvider ,
21
+ useVoice
22
+ } from '@deep-foundation/deepmemo-imports/imports/voice' ;
19
23
import {
20
24
GeolocationProvider ,
21
25
useGeolocation
@@ -24,6 +28,7 @@ import React, { useEffect, useRef, useState } from 'react';
24
28
import { Connection } from '../src/connection' ;
25
29
import { i18nGetStaticProps } from '../src/i18n' ;
26
30
import { SaverProvider } from '@deep-foundation/deepmemo-imports/imports/saver' ;
31
+ import { useLocalStore } from '@deep-foundation/store/local' ;
27
32
28
33
const Loading = React . memo ( function Loading ( { factor, interval } : { factor : any , interval : number } ) {
29
34
const [ value , setValue ] = useState ( 0 ) ;
@@ -117,6 +122,58 @@ const GeolocationView = React.memo(function GeolocationView({ interval }: { inte
117
122
</ > ;
118
123
} ) ;
119
124
125
+ const VoiceView = React . memo ( function VoiceView ( ) {
126
+ const deep = useDeep ( ) ;
127
+ const voice = useVoice ( ) ;
128
+ const [ voices , setVoices ] = useState ( [ ] ) ;
129
+ const [ active , setActive ] = useState ( - 1 ) ;
130
+ return < >
131
+ < Heading > Voice</ Heading >
132
+ < Box >
133
+ { voices . map ( ( v , i ) => < Button key = { i }
134
+ onClick = { ( ) => setActive ( id => i === id ? - 1 : i ) }
135
+ variant = { active === i ? 'solid' : 'outline' }
136
+ > { v ?. id || i } </ Button > ) }
137
+ < Box >
138
+ </ Box >
139
+ { active >= 0 && < audio controls >
140
+ < source src = { `data:audio/mpeg;base64,${ voices [ active ] ?. record } ` } type = "audio/mpeg" > </ source >
141
+ </ audio > }
142
+ </ Box >
143
+ { voice . status ? (
144
+ voice . recording ? ( < >
145
+ < Button onClick = { async ( ) => {
146
+ const record = await voice . stop ( ) ;
147
+ setVoices ( v => [ ...v , record ] ) ;
148
+ } } > stop</ Button >
149
+ { voice . paused ? (
150
+ < Button onClick = { ( ) => voice . pause ( ) } > pause</ Button >
151
+ ) : (
152
+ < Button onClick = { ( ) => voice . resume ( ) } > resume</ Button >
153
+ ) }
154
+ </ > ) : (
155
+ < Button onClick = { ( ) => voice . start ( ) } > start</ Button >
156
+ )
157
+ ) : (
158
+ < Button onClick = { ( ) => voice . request ( ) } > request</ Button >
159
+ ) }
160
+ </ > ;
161
+ } ) ;
162
+
163
+ export function Syncing ( { title, value, setValue } ) {
164
+ const deep = useDeep ( ) ;
165
+ return < FormControl display = 'flex' alignItems = 'center' >
166
+ < FormLabel htmlFor = 'syncing' mb = '0' >
167
+ { title }
168
+ </ FormLabel >
169
+ < Switch id = 'syncing'
170
+ isChecked = { value }
171
+ onChange = { ( ) => setValue ( s => ! s ) }
172
+ disabled = { ! deep ?. id }
173
+ />
174
+ </ FormControl > ;
175
+ }
176
+
120
177
export default function Page ( ) {
121
178
const deep = useDeep ( ) ;
122
179
const toast = useToast ( ) ;
@@ -125,39 +182,49 @@ export default function Page() {
125
182
if ( typeof ( window ) === 'object' ) window . deep = deep ;
126
183
console . log ( 'deep' , deep ) ;
127
184
185
+ const [ containerId , setContainerId ] = useLocalStore ( 'deepmemo-app-containerId' , null ) ;
128
186
const [ deviceInterval , setDeviceInterval ] = useState ( 5000 ) ;
187
+ const [ deviceSaver , setDeviceSaver ] = useState ( true ) ;
129
188
const [ geolocationInterval , setGeolocationInterval ] = useState ( 5000 ) ;
189
+ const [ geolocationSaver , setGeolocationSaver ] = useState ( true ) ;
130
190
const [ saver , setSaver ] = useState < boolean > ( false ) ;
131
191
useEffect ( ( ) => {
132
192
if ( ! deep ) setSaver ( false ) ;
193
+ else deep . local = false ;
133
194
} , [ deep ] ) ;
134
195
135
196
return ( < >
136
197
< Connection />
137
198
< Box p = { 4 } >
138
- < FormControl display = 'flex' alignItems = 'center' >
139
- < FormLabel htmlFor = 'syncing' mb = '0' >
140
- Enable syncing with deep backend?
141
- </ FormLabel >
142
- < Switch id = 'syncing'
143
- isChecked = { saver }
144
- onChange = { ( ) => setSaver ( s => ! s ) }
145
- disabled = { ! deep ?. id }
146
- />
147
- </ FormControl >
199
+ < Syncing title = { 'Enable syncing with deep backend?' } value = { saver } setValue = { setSaver } />
200
+ < FormControl display = 'flex' alignItems = 'center' >
201
+ < FormLabel htmlFor = 'syncing' mb = '0' >
202
+ ContainerId
203
+ </ FormLabel >
204
+ < Input
205
+ placeholder = { `${ deep ?. linkId } ` }
206
+ value = { containerId } onChange = { ( e ) => setContainerId ( e . target . value ) }
207
+ w = { '10em' }
208
+ />
209
+ </ FormControl >
148
210
< SaverProvider onSave = { ( { Type, id, object, mode, promise } ) => {
149
211
toast . promise ( promise , {
150
212
success : { title : `Saved ${ mode } #${ id || '?' } of type (#${ Type } ) to deep` , isClosable : true } ,
151
- error : { title : `Error with saving ${ mode } #${ id || '?' } of type (#${ Type } ) to deep` , isClosable : true } ,
213
+ error : ( e ) => ( { title : `Error with saving ${ mode } #${ id || '?' } of type (#${ Type } ) to deep` , description : e . toString ( ) , isClosable : true } ) ,
152
214
loading : { title : `Saving ${ mode } #${ id || '?' } of type (#${ Type } ) to deep` , isClosable : true } ,
153
215
} )
154
216
} } >
155
- < DeviceProvider saver = { saver } containerId = { deep ?. linkId } interval = { deviceInterval } >
156
- < GeolocationProvider saver = { saver } interval = { geolocationInterval } >
157
- < Interval value = { deviceInterval } onChange = { setDeviceInterval } />
158
- < DeviceView interval = { deviceInterval } />
159
- < Interval value = { geolocationInterval } onChange = { setGeolocationInterval } />
160
- < GeolocationView interval = { geolocationInterval } />
217
+ < DeviceProvider saver = { saver && deviceSaver } containerId = { containerId } interval = { deviceInterval } >
218
+ < GeolocationProvider saver = { saver && geolocationSaver } interval = { geolocationInterval } >
219
+ < VoiceProvider saver = { saver } >
220
+ < VoiceView />
221
+ < Interval value = { deviceInterval } onChange = { setDeviceInterval } />
222
+ < Syncing title = { 'Enable voice syncing with deep backend?' } value = { deviceSaver } setValue = { setDeviceSaver } />
223
+ < DeviceView interval = { deviceInterval } />
224
+ < Interval value = { geolocationInterval } onChange = { setGeolocationInterval } />
225
+ < Syncing title = { 'Enable geolocation syncing with deep backend?' } value = { geolocationSaver } setValue = { setGeolocationSaver } />
226
+ < GeolocationView interval = { geolocationInterval } />
227
+ </ VoiceProvider >
161
228
</ GeolocationProvider >
162
229
</ DeviceProvider >
163
230
</ SaverProvider >
0 commit comments