-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathApp.js
More file actions
118 lines (104 loc) · 3.49 KB
/
App.js
File metadata and controls
118 lines (104 loc) · 3.49 KB
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
108
109
110
111
112
113
114
115
116
117
118
import { StatusBar } from 'expo-status-bar';
import React, { useEffect, useState } from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';
import MainScreen from './components/MainScreen.js';
import RegisterScreen from './components/RegisterScreen.js';
import Dashboard from './components/Dashboard.js'
import EnrollScreen from './components/EnrollScreen.js';
import CreateScreen from './components/CreateScreen.js';
import RegisterOptionsScreen from './components/RegisterOptionsScreen.js';
import AddAssignmentScreen from './components/AddAssignmentScreen.js';
import AddClassScreen from './components/AddClassScreen.js';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import fire from './fire.js'
const Stack = createStackNavigator();
function App() {
const [user, setUser] = useState(null);
//Loading screen for when firebase data is being retrieved
const [loading, setLoading] = useState(true);
useEffect(() => {
const usersRef = fire.firestore().collection('users');
//Returns currently logged in user
fire.auth().onAuthStateChanged(user => {
if(user) {
usersRef.doc(user.uid).get().then(document => {
const userData = document.data()
setUser(userData)
setLoading(false)
}).catch(error => {
console.log(error);
setLoading(false);
})
} else {
console.log("huh?")
setLoading(false)
}
})
}, []);
if(loading) {
// Add a proper loading design here
return (
<Text>Hiaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</ Text>
)
}
return (
<NavigationContainer>
{/* If user is logged in when launched, send straight to Dashboard */}
<Stack.Navigator initialRouteName={user ? "Dashboard" : "Main"}>
<Stack.Screen name="Dashboard" options={{
gestureEnabled: false,
headerShown: false,
cardStyle: {
backgroundColor: 'white'
}
}}>
{props => <Dashboard {...props} />}
</Stack.Screen>
<Stack.Screen name="Main" component={MainScreen} options={{
gestureEnabled: false,
headerShown: false,
cardStyle: {
backgroundColor: 'white'
}
}}/>
<Stack.Screen name="Register" component={RegisterScreen} options={{
cardStyle: {
backgroundColor: 'white'
}
}} />
<Stack.Screen name="Enroll" component={EnrollScreen} options={{
cardStyle: {
backgroundColor: 'white'
}
}} />
<Stack.Screen name="Create" component={CreateScreen} options={{
cardStyle: {
backgroundColor: 'white'
}
}} />
<Stack.Screen name="RegisterOptions" component={RegisterOptionsScreen} options={{
title: 'Options',
gestureEnabled: false,
headerLeft: null,
cardStyle: {
backgroundColor: 'white'
}
}} />
<Stack.Screen name="AddAssignment" component={AddAssignmentScreen} options={{
title: 'Add Assignment',
cardStyle: {
backgroundColor: 'white'
}
}} />
<Stack.Screen name="AddClass" component={AddClassScreen} options={{
title: 'Add Class',
cardStyle: {
backgroundColor: 'white'
}
}} />
</Stack.Navigator>
</NavigationContainer>
);
}
export default App;