Skip to content

Commit 837d2a3

Browse files
committed
fixed bug with settingsfetch
1 parent 59ef694 commit 837d2a3

File tree

6 files changed

+39
-29
lines changed

6 files changed

+39
-29
lines changed

app/components/wallpaper/bg.png

-43.5 KB
Loading
-164 KB
Loading

app/screens/graph/graph-screen.tsx

+23-22
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import genRandomTree from "../../data/randomdata"
1313

1414
import AsyncStorage from "@react-native-async-storage/async-storage"
1515

16+
import axios from "axios";
17+
1618
const ROOT: ViewStyle = {
1719
backgroundColor: color.palette.black,
1820
flex: 1,
@@ -24,10 +26,6 @@ export const GraphScreen = observer(function GraphScreen() {
2426

2527
// Pull in navigation via hook
2628
// 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)
3129

3230
const [physics, setPhysics] = useState({})
3331
const physicsInit = {
@@ -43,50 +41,53 @@ export const GraphScreen = observer(function GraphScreen() {
4341
particleWidth: 1,
4442
nodeRel: 1,
4543
}
44+
4645
const getData = async () => {
4746
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 };
5153
} else {
52-
console.log(physicsInit)
5354
return physicsInit
5455
}
5556
} catch (e) {
5657
console.log(e)
5758
}
5859
}
5960

61+
//"ComponentOnMount"
62+
// Get previous settings and the data from the org-roam-server
6063
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+
//});
6271
}, [])
6372

6473
const storeData = async (value) => {
6574
try {
6675
const jsonValue = JSON.stringify(value)
67-
await AsyncStorage.setItem("@physics", jsonValue)
76+
await AsyncStorage.mergeItem("@physics", jsonValue)
6877
console.log("Writing " + jsonValue)
6978
} catch (e) {
7079
console.log(e)
7180
}
7281
}
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
8385
useEffect(() => {
8486
if (timer) {
8587
clearTimeout(timer)
86-
console.log("clear timer")
8788
}
89+
// set timer so the thing doesn't run every single slider tick
8890
const timer = setTimeout(() => {
89-
console.log("Physics changed")
9091
storeData(physics)
9192
const test = getData()
9293
console.log(test)

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@
3535
"@react-native-community/slider": "^3.0.3",
3636
"@react-navigation/native": "5.9.3",
3737
"@react-navigation/stack": "5.12.8",
38+
"@types/axios": "^0.14.0",
3839
"@types/react-native-collapsible": "^0.11.0",
3940
"@unimodules/core": "6.0.0",
4041
"apisauce": "2.0.0",
42+
"axios": "^0.21.1",
4143
"d3-force": "^3.0.0",
4244
"expo": "40.0.1",
4345
"expo-localization": "9.1.0",

screenshot.png

-39.3 KB
Loading

yarn.lock

+14-7
Original file line numberDiff line numberDiff line change
@@ -3272,6 +3272,13 @@
32723272
resolved "https://registry.yarnpkg.com/@tweenjs/tween.js/-/tween.js-18.6.4.tgz#40a3d0a93647124872dec8e0fd1bd5926695b6ca"
32733273
integrity sha512-lB9lMjuqjtuJrx7/kOkqQBtllspPIN+96OvTCeJ2j5FEzinoAXTdAMFnDAQT1KVPRlnYfBrqxtqP66vDM40xxQ==
32743274

3275+
"@types/axios@^0.14.0":
3276+
version "0.14.0"
3277+
resolved "https://registry.yarnpkg.com/@types/axios/-/axios-0.14.0.tgz#ec2300fbe7d7dddd7eb9d3abf87999964cafce46"
3278+
integrity sha1-7CMA++fX3d1+udOr+HmZlkyvzkY=
3279+
dependencies:
3280+
axios "*"
3281+
32753282
"@types/babel__core@^7.0.0", "@types/babel__core@^7.1.7":
32763283
version "7.1.15"
32773284
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.15.tgz#2ccfb1ad55a02c83f8e0ad327cbc332f55eb1024"
@@ -4791,6 +4798,13 @@ aws4@^1.8.0:
47914798
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59"
47924799
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==
47934800

4801+
axios@*, axios@^0.21.0, axios@^0.21.1:
4802+
version "0.21.1"
4803+
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8"
4804+
integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==
4805+
dependencies:
4806+
follow-redirects "^1.10.0"
4807+
47944808
axios@^0.16.2:
47954809
version "0.16.2"
47964810
resolved "https://registry.yarnpkg.com/axios/-/axios-0.16.2.tgz#ba4f92f17167dfbab40983785454b9ac149c3c6d"
@@ -4799,13 +4813,6 @@ axios@^0.16.2:
47994813
follow-redirects "^1.2.3"
48004814
is-buffer "^1.1.5"
48014815

4802-
axios@^0.21.0:
4803-
version "0.21.1"
4804-
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8"
4805-
integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==
4806-
dependencies:
4807-
follow-redirects "^1.10.0"
4808-
48094816
48104817
version "0.19.0-beta.1"
48114818
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.0-beta.1.tgz#3d6a9ee75885d1fd39e108df9a4fb2e48e1af1e8"

0 commit comments

Comments
 (0)