-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathApp.tsx
76 lines (67 loc) · 2.52 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
import React, { useEffect, useState } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import auth from '@react-native-firebase/auth';
// import screen
import Index from './screens/index';
import LoginPage from './screens/login';
import LoadingPage from './screens/loading';
import RegisterPage from './screens/register';
import AccountPage from './screens/account';
import PetGroomer from './screens/petGroomer';
import AddressPage from './screens/address';
import ProgressPage from './screens/progress';
import AdminDashboard from './screens/admin';
const Stack = createNativeStackNavigator();
const App = () => {
// variables
const [isLoading, setLoading] = useState(false);
const [isLoggedIn, setLoggedIn] = useState(false);
useEffect(() => { // using useEffect so that the app can run many task at the same time
checkLoginStatus();
}, []);
// cheking login status using async storage that store data locally
const checkLoginStatus = async () => {
setLoading(true);
try {
// using email as an id
const user = auth().currentUser;
if (user !== null) {
setLoggedIn(true);
}
} catch (error) {
console.log("Error Retrieving user token: ", error);
} finally {
setLoading(false);
}
};
// while fetching the data, the app shows a loading screen
if (isLoading) {
return <LoadingPage />;
}
return (
// <NavigationContainer>
// <ProgressPage/>
// </NavigationContainer>
<NavigationContainer>
{/* <Index/> */}
{/* Cheking whether user data is stored (isLoggedIn) or not */}
<Stack.Navigator initialRouteName={isLoggedIn ? 'Index' : 'Login'}
screenOptions={{
headerTitleAlign: 'center',
headerTitleStyle: {
fontWeight: 'bold',
},
}}>
{/* <Stack.Navigator initialRouteName='Index'> */}
<Stack.Screen name='Login' component={LoginPage} options={{ headerShown: false }} />
<Stack.Screen name='Register' component={RegisterPage} options={{ headerShown: false }} />
<Stack.Screen name='Index' component={Index} options={{ headerShown: false }} />
<Stack.Screen name ='Account' component={AccountPage} />
<Stack.Screen name ='Address' component={AddressPage} />
<Stack.Screen name= 'Admin Dashboard' component={AdminDashboard} options={{headerShown: false}}/>
</Stack.Navigator>
</NavigationContainer>
);
}
export default App;