-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.tsx
94 lines (82 loc) · 2.69 KB
/
App.tsx
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
import React, {useState} from 'react';
import {useNetInfo} from '@react-native-community/netinfo';
import {NavigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import UserAuth from './components/organism/1_user-auth';
import HomeNavigation from './components/organism/2_home';
import Loading from './components/organism/3_loading';
import firestore from '@react-native-firebase/firestore';
import AsyncStorage from '@react-native-async-storage/async-storage';
function App() {
const netInfo = useNetInfo();
const Stack = createStackNavigator();
const [isDarkMode, setIsDarkMode] = useState(true);
const [userID, setUserID] = useState('');
const [isLoggedIn, setIsLoggedIn] = useState(false);
const [profileData, setProfileData] = useState({});
const refetchProfile = async () => {
try {
const userDocument = await firestore()
.collection('Users')
.doc(userID)
.get();
if (userDocument.exists) {
const userData = userDocument.data();
// @ts-ignore
setProfileData(userData);
await AsyncStorage.setItem('data', JSON.stringify(userData));
} else {
console.log('Document does not exist');
}
} catch (error) {
console.log('Error Fetching Profile');
}
};
return (
<NavigationContainer>
<Stack.Navigator
initialRouteName="Loading"
screenOptions={{
headerShown: false,
animationEnabled: true,
}}>
<Stack.Screen name="Loading" options={{headerShown: false}}>
{props => (
<Loading
{...props}
setUserID={setUserID}
setIsLoggedIn={setIsLoggedIn}
setProfileData={setProfileData}
/>
)}
</Stack.Screen>
<Stack.Screen name="Auth" options={{headerShown: false}}>
{props => (
<UserAuth
{...props}
isDarkMode={isDarkMode}
netInfo={netInfo}
setUserID={setUserID}
setIsLoggedIn={setIsLoggedIn}
setProfileData={setProfileData}
setIsDarkMode={setIsDarkMode}
/>
)}
</Stack.Screen>
<Stack.Screen name="Home" options={{headerShown: false}}>
{props => (
<HomeNavigation
{...props}
isDarkMode={isDarkMode}
userID={userID}
profileData={profileData}
setIsDarkMode={setIsDarkMode}
refetchProfile={refetchProfile}
/>
)}
</Stack.Screen>
</Stack.Navigator>
</NavigationContainer>
);
}
export default App;