1
1
import {
2
- Box , Button , CircularProgress , CircularProgressLabel , Heading , SimpleGrid ,
2
+ Box , Button , CircularProgress , CircularProgressLabel , FormControl , FormLabel , Heading , SimpleGrid ,
3
3
Slider ,
4
4
SliderFilledTrack ,
5
5
SliderMark ,
6
6
SliderThumb ,
7
7
SliderTrack ,
8
+ Switch ,
9
+ useToast ,
8
10
} from '@chakra-ui/react' ;
9
11
import CytoGraph from '@deep-foundation/deepcase/imports/cyto/graph' ;
10
12
import { useRefstarter } from '@deep-foundation/deepcase/imports/refstater' ;
@@ -21,6 +23,7 @@ import {
21
23
import React , { useEffect , useRef , useState } from 'react' ;
22
24
import { Connection } from '../src/connection' ;
23
25
import { i18nGetStaticProps } from '../src/i18n' ;
26
+ import { SaverProvider } from '@deep-foundation/deepmemo-imports/imports/saver' ;
24
27
25
28
const Loading = React . memo ( function Loading ( { factor, interval } : { factor : any , interval : number } ) {
26
29
const [ value , setValue ] = useState ( 0 ) ;
@@ -72,8 +75,16 @@ const Graph = React.memo(function Graph({ linkId }: { linkId: Id }) {
72
75
const deep = useDeep ( ) ;
73
76
const cyRef = useRef ( ) ;
74
77
const cytoViewportRef = useRefstarter < { pan : { x : number ; y : number ; } ; zoom : number } > ( ) ;
75
- const { data : containTree } = deep . useDeepId ( '@deep-foundation/core' , 'containTree' ) ;
76
- const { data : links = [ ] } : { data ?: Link < Id > [ ] } = deep . useDeepSubscription ( { up : { parent_id : linkId || 0 , tree_id : containTree || 0 } } ) ;
78
+ const { data : links = [ ] } : { data ?: Link < Id > [ ] } = deep . useDeepSubscription ( {
79
+ up : { parent_id : linkId || 0 , tree_id : deep . idLocal ( '@deep-foundation/core' , 'containTree' ) } ,
80
+ _not : { type_id : { _in : [
81
+ deep . idLocal ( '@deep-foundation/core' , 'Promise' ) ,
82
+ deep . idLocal ( '@deep-foundation/core' , 'Then' ) ,
83
+ deep . idLocal ( '@deep-foundation/core' , 'Resolved' ) ,
84
+ deep . idLocal ( '@deep-foundation/core' , 'Rejected' ) ,
85
+ deep . idLocal ( '@deep-foundation/core' , 'PromiseResult' ) ,
86
+ ] } } ,
87
+ } ) ;
77
88
return < >
78
89
{ ! ! linkId && < Box w = { 500 } h = { 500 } border = { '1px' } rounded = 'md' position = "relative" >
79
90
{ deep ?. linkId && < CytoGraph links = { links } cyRef = { cyRef } cytoViewportRef = { cytoViewportRef } /> }
@@ -85,7 +96,7 @@ const DeviceView = React.memo(function DeviceView({ interval }: { interval: numb
85
96
const deep = useDeep ( ) ;
86
97
const device = useDevice ( ) ;
87
98
return < >
88
- < Heading > Device { device ?. id ? < > { device ?. id } </ > : < > { 'syncing ' } </ > } < Loading factor = { device } interval = { interval } /> </ Heading >
99
+ < Heading > Device { device ?. id ? < > { device ?. id } </ > : < > { 'id not defined ' } </ > } < Loading factor = { device } interval = { interval } /> </ Heading >
89
100
< SimpleGrid columns = { { sm : 1 , md : 2 } } >
90
101
< Box > < pre > { JSON . stringify ( device , null , 2 ) } </ pre > </ Box >
91
102
{ deep ?. linkId && device ?. id && < Graph linkId = { device . id } /> }
@@ -97,35 +108,59 @@ const GeolocationView = React.memo(function GeolocationView({ interval }: { inte
97
108
const deep = useDeep ( ) ;
98
109
const geolocation = useGeolocation ( ) ;
99
110
return < >
100
- < Heading > Geolocation < > < Loading factor = { geolocation . position } interval = { interval } /> </ > </ Heading >
111
+ < Heading > Geolocation { geolocation ?. position ?. id ? < > { geolocation ?. position ?. id } </ > : < > { 'id not defined' } </ > } < > < Loading factor = { geolocation . position } interval = { interval } /> </ > </ Heading >
101
112
< Button onClick = { ( ) => geolocation . request ( ) } > request</ Button >
102
113
< SimpleGrid columns = { { sm : 1 , md : 2 } } >
103
114
< Box > < pre > { JSON . stringify ( geolocation , null , 2 ) } </ pre > </ Box >
115
+ { deep ?. linkId && geolocation ?. position ?. id && < Graph linkId = { geolocation . position . id } /> }
104
116
</ SimpleGrid >
105
117
</ > ;
106
118
} ) ;
107
119
108
120
export default function Page ( ) {
109
121
const deep = useDeep ( ) ;
122
+ const toast = useToast ( ) ;
110
123
111
124
// @ts -ignore
112
125
if ( typeof ( window ) === 'object' ) window . deep = deep ;
113
126
console . log ( 'deep' , deep ) ;
114
127
115
128
const [ deviceInterval , setDeviceInterval ] = useState ( 5000 ) ;
116
129
const [ geolocationInterval , setGeolocationInterval ] = useState ( 5000 ) ;
130
+ const [ saver , setSaver ] = useState < boolean > ( false ) ;
131
+ useEffect ( ( ) => {
132
+ if ( ! deep ) setSaver ( false ) ;
133
+ } , [ deep ] ) ;
117
134
118
135
return ( < >
119
136
< Connection />
120
137
< Box p = { 4 } >
121
- < DeviceProvider containerId = { deep ?. linkId } interval = { deviceInterval } >
122
- < GeolocationProvider containerId = { deep ?. linkId } interval = { geolocationInterval } >
123
- < Interval value = { deviceInterval } onChange = { setDeviceInterval } />
124
- < DeviceView interval = { deviceInterval } />
125
- < Interval value = { geolocationInterval } onChange = { setGeolocationInterval } />
126
- < GeolocationView interval = { geolocationInterval } />
127
- </ GeolocationProvider >
128
- </ DeviceProvider >
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 >
148
+ < SaverProvider onSave = { ( { Type, id, object, mode, promise } ) => {
149
+ toast . promise ( promise , {
150
+ 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 } ,
152
+ loading : { title : `Saving ${ mode } #${ id || '?' } of type (#${ Type } ) to deep` , isClosable : true } ,
153
+ } )
154
+ } } >
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 } />
161
+ </ GeolocationProvider >
162
+ </ DeviceProvider >
163
+ </ SaverProvider >
129
164
</ Box >
130
165
</ > ) ;
131
166
}
0 commit comments