Skip to content

Commit e8b9db6

Browse files
committed
0.0.5
1 parent a5150f7 commit e8b9db6

File tree

3 files changed

+59
-24
lines changed

3 files changed

+59
-24
lines changed

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@deep-foundation/deepmemo-app",
3-
"version": "0.0.4",
3+
"version": "0.0.5",
44
"description": "",
55
"license": "Unlicense",
66
"main": "./bin/server.js",
@@ -35,7 +35,7 @@
3535
"@capacitor/geolocation": "^5.0.7",
3636
"@deep-foundation/deepcase": "^0.0.121",
3737
"@deep-foundation/deeplinks": "^0.0.343",
38-
"@deep-foundation/deepmemo-imports": "^0.0.5",
38+
"@deep-foundation/deepmemo-imports": "^0.0.6",
3939
"@solid-primitives/geolocation": "^1.4.14",
4040
"dotenv-load": "^2.0.1",
4141
"next": "^14.2.2",

pages/index.tsx

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {
2-
Box, Button, CircularProgress, CircularProgressLabel, Heading, SimpleGrid,
2+
Box, Button, CircularProgress, CircularProgressLabel, FormControl, FormLabel, Heading, SimpleGrid,
33
Slider,
44
SliderFilledTrack,
55
SliderMark,
66
SliderThumb,
77
SliderTrack,
8+
Switch,
9+
useToast,
810
} from '@chakra-ui/react';
911
import CytoGraph from '@deep-foundation/deepcase/imports/cyto/graph';
1012
import { useRefstarter } from '@deep-foundation/deepcase/imports/refstater';
@@ -21,6 +23,7 @@ import {
2123
import React, { useEffect, useRef, useState } from 'react';
2224
import { Connection } from '../src/connection';
2325
import { i18nGetStaticProps } from '../src/i18n';
26+
import { SaverProvider } from '@deep-foundation/deepmemo-imports/imports/saver';
2427

2528
const Loading = React.memo(function Loading({ factor, interval }: { factor: any, interval: number }) {
2629
const [value, setValue] = useState(0);
@@ -72,8 +75,16 @@ const Graph = React.memo(function Graph({ linkId }: { linkId: Id }) {
7275
const deep = useDeep();
7376
const cyRef = useRef();
7477
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+
});
7788
return <>
7889
{!!linkId && <Box w={500} h={500} border={'1px'} rounded='md' position="relative">
7990
{deep?.linkId && <CytoGraph links={links} cyRef={cyRef} cytoViewportRef={cytoViewportRef}/>}
@@ -85,7 +96,7 @@ const DeviceView = React.memo(function DeviceView({ interval }: { interval: numb
8596
const deep = useDeep();
8697
const device = useDevice();
8798
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>
89100
<SimpleGrid columns={{sm: 1, md: 2}}>
90101
<Box><pre>{JSON.stringify(device, null, 2)}</pre></Box>
91102
{deep?.linkId && device?.id && <Graph linkId={device.id}/>}
@@ -97,35 +108,59 @@ const GeolocationView = React.memo(function GeolocationView({ interval }: { inte
97108
const deep = useDeep();
98109
const geolocation = useGeolocation();
99110
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>
101112
<Button onClick={() => geolocation.request()}>request</Button>
102113
<SimpleGrid columns={{sm: 1, md: 2}}>
103114
<Box><pre>{JSON.stringify(geolocation, null, 2)}</pre></Box>
115+
{deep?.linkId && geolocation?.position?.id && <Graph linkId={geolocation.position.id}/>}
104116
</SimpleGrid>
105117
</>;
106118
});
107119

108120
export default function Page() {
109121
const deep = useDeep();
122+
const toast = useToast();
110123

111124
// @ts-ignore
112125
if (typeof(window) === 'object') window.deep = deep;
113126
console.log('deep', deep);
114127

115128
const [deviceInterval, setDeviceInterval] = useState(5000);
116129
const [geolocationInterval, setGeolocationInterval] = useState(5000);
130+
const [saver, setSaver] = useState<boolean>(false);
131+
useEffect(() => {
132+
if (!deep) setSaver(false);
133+
}, [deep]);
117134

118135
return (<>
119136
<Connection/>
120137
<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>
129164
</Box>
130165
</>);
131166
}

0 commit comments

Comments
 (0)