-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
107 lines (90 loc) · 2.87 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import React, { useState, useEffect } from "react";
import { StyleSheet, } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import { Fire } from "./firebase";
import { PageContext } from "./context";
import "react-native-gesture-handler";
import { LoginStack } from "./navigation/LoginStack";
const fire = new Fire();
let initialRender = true;
export default function App() {
const [authID, setAuthID] = useState("");
const [lists, setLists] = useState([]);
const [refresh, setRefresh] = useState(false);
const [vitalsigns, setVitalsigns] = useState([]);
const [points, setPoints] = useState(0);
const [count, setCount] = useState(0);
const [header, setHeader] = useState("");
const [name, setName] = useState("");
// useEffect is a Effect hook that triggers depending on render
// this useEffect triggers once when App.js renders, when triggered it calls the firebase getLists function
// to retrieve the data from the Database, after the cleanup function is called to unsubscribe to the firebase
// listener that recieves the data
useEffect(() => {
// prevents the useEffect from doing anything on first render
if (initialRender) {
initialRender = false;
} else {
// Retrieves the lists from the users database
fire.getLists((lists) => {
setLists(lists);
});
fire.getVitalSigns((vitalsign) => {
setVitalsigns(vitalsign);
});
// fire.getUserData((data) => {
// setUserData(data);
// setPoints(data[1].userPoints)
// });
// Retrieves the points from the user database
fire.refUser.get().then((doc) => {
setPoints(doc.data().userPoints);
setCount(doc.data().counter);
});
// Unsubscribes to the lists listener
return fire.detach();
}
// Updates on authID change
}, [authID]);
return (
// PageContext enables the child components to have access to values set by the provider
// The values can be accessed in any file under its tag with the use of 'useContext'
<PageContext.Provider
value={{
fire: fire,
lists: lists,
authen: [authID, setAuthID],
namee: [name, setName],
refreshs: [refresh, setRefresh],
vitals: [vitalsigns, setVitalsigns],
pointss: [points, setPoints],
counter: [count, setCount],
headers: [header, setHeader],
}}
>
{/* <StatusBar barStyle="dark-content" /> */}
<NavigationContainer>
<LoginStack/>
</NavigationContainer>
</PageContext.Provider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "blue",
alignItems: "center",
justifyContent: "center",
},
safeArea: {
flex: 1,
overflow: 'hidden',
},
background: {
position: 'absolute',
left: 0,
right: 0,
top: 0,
height: 300,
},
});