@@ -13,6 +13,8 @@ import genRandomTree from "../../data/randomdata"
13
13
14
14
import AsyncStorage from "@react-native-async-storage/async-storage"
15
15
16
+ import axios from "axios" ;
17
+
16
18
const ROOT : ViewStyle = {
17
19
backgroundColor : color . palette . black ,
18
20
flex : 1 ,
@@ -24,10 +26,6 @@ export const GraphScreen = observer(function GraphScreen() {
24
26
25
27
// Pull in navigation via hook
26
28
// const navigation = useNavigation()
27
- const [ charge , setCharge ] = useState ( - 30 )
28
- const [ collision , setCollision ] = useState ( false )
29
- const [ linkStrength , setLinkStrength ] = useState ( 1 )
30
- const [ linkIts , setLinkIts ] = useState ( 1 )
31
29
32
30
const [ physics , setPhysics ] = useState ( { } )
33
31
const physicsInit = {
@@ -43,50 +41,53 @@ export const GraphScreen = observer(function GraphScreen() {
43
41
particleWidth : 1 ,
44
42
nodeRel : 1 ,
45
43
}
44
+
46
45
const getData = async ( ) => {
47
46
try {
48
- const value = await AsyncStorage . getItem ( "@physics" )
49
- if ( value !== null || keys ( value ) === keys ( physicsInit ) ) {
50
- return JSON . parse ( value )
47
+ const value : string = await AsyncStorage . getItem ( "@physics" ) ;
48
+ if ( value !== null ) {
49
+ const valueJson = JSON . parse ( value ) ;
50
+ if ( Object . keys ( valueJson ) . length === Object . keys ( physicsInit ) . length ) {
51
+ return valueJson ;
52
+ } else { return physicsInit } ;
51
53
} else {
52
- console . log ( physicsInit )
53
54
return physicsInit
54
55
}
55
56
} catch ( e ) {
56
57
console . log ( e )
57
58
}
58
59
}
59
60
61
+ //"ComponentOnMount"
62
+ // Get previous settings and the data from the org-roam-server
60
63
useEffect ( ( ) => {
61
- getData ( ) . then ( ( data ) => setPhysics ( data ) )
64
+ getData ( ) . then ( ( data ) => setPhysics ( data ) ) ;
65
+ // axios.get('/roamData')
66
+ // .then(()=>console.log("Whoo got data"))
67
+ //.catch((e)=>{
68
+ // console.log(e);
69
+ // console.log("Couldn't get data.");
70
+ //});
62
71
} , [ ] )
63
72
64
73
const storeData = async ( value ) => {
65
74
try {
66
75
const jsonValue = JSON . stringify ( value )
67
- await AsyncStorage . setItem ( "@physics" , jsonValue )
76
+ await AsyncStorage . mergeItem ( "@physics" , jsonValue )
68
77
console . log ( "Writing " + jsonValue )
69
78
} catch ( e ) {
70
79
console . log ( e )
71
80
}
72
81
}
73
- /* const [physics, setPhysics] = useState(
74
- * {
75
- * charge: -30,
76
- * collision: false,
77
- * linkStrength: 1,
78
- * linkIts: 1,
79
- * collapse: false,
80
- * threedim: false,
81
- * particles: 2,
82
- * }); */
82
+
83
+ // hook to save the current configuration of the physics tweaks
84
+ // after it is updated
83
85
useEffect ( ( ) => {
84
86
if ( timer ) {
85
87
clearTimeout ( timer )
86
- console . log ( "clear timer" )
87
88
}
89
+ // set timer so the thing doesn't run every single slider tick
88
90
const timer = setTimeout ( ( ) => {
89
- console . log ( "Physics changed" )
90
91
storeData ( physics )
91
92
const test = getData ( )
92
93
console . log ( test )
0 commit comments