-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
162 lines (138 loc) · 4.42 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import 'react-native-gesture-handler';
import React, { useContext, useEffect, useState } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { StatusBar } from 'expo-status-bar';
import AsyncStorage from '@react-native-async-storage/async-storage';
import AppLoading from 'expo-app-loading';
import LoginScreen from './screens/LoginScreen';
import SignupScreen from './screens/SignupScreen';
import WelcomeScreen from './screens/WelcomeScreen';
import { Colors } from './constants/styles';
import AuthContextProvider, { AuthContext } from './store/auth-context';
import IconButton from './components/ui/IconButton';
import Home from "./screens/Home";
import Projects from "./screens/Projects";
import Profile from "./screens/Profile";
import Sidebar from "./screens/Sidebar";
import {createDrawerNavigator, DrawerContentScrollView, DrawerItem, DrawerItemList} from "@react-navigation/drawer";
import Tasks from "./screens/Tasks";
import {getAllProjects} from "./features/project/projectSlice";
import {store} from "./store";
import {Provider} from "react-redux";
import {Icon} from "@rneui/themed";
const Stack = createNativeStackNavigator();
const Drawer = createDrawerNavigator();
function AuthStack() {
return (
<Stack.Navigator
screenOptions={{
headerStyle: { backgroundColor: "#0097e6" },
headerTintColor: 'white',
contentStyle: { backgroundColor: "#f5f6fa" },
}}
>
<Stack.Screen name="Login" component={LoginScreen} />
<Stack.Screen name="Signup" component={SignupScreen} />
</Stack.Navigator>
);
}
function AuthenticatedStack() {
const authCtx = useContext(AuthContext);
const CustomDrawerContent = (props) => {
return(
<DrawerContentScrollView {...props}>
<DrawerItemList {...props} />
<DrawerItem
label="Logout"
onPress={() => {authCtx.logout()}}
icon={() => <Icon name="logout" color="#000" size={24} />}
/>
</DrawerContentScrollView>
);
}
return (
/*<Stack.Navigator
screenOptions={{
headerStyle: { backgroundColor: Colors.primary500 },
headerTintColor: 'white',
contentStyle: { backgroundColor: Colors.primary100 },
}}
>
<Stack.Screen
name="Home"
component={Main}
options={{
headerRight: ({ tintColor }) => (
<IconButton
icon="exit"
color={tintColor}
size={24}
onPress={authCtx.logout}
/>
),
}}
/>
</Stack.Navigator>*/
<Provider store={store}>
<Drawer.Navigator drawerContent={(props) => <CustomDrawerContent {...props}
options={{
headerRight: ({ tintColor }) => (
<IconButton
icon="exit"
color={tintColor}
size={24}
onPress={authCtx.logout}
/>
),
}
}
/>}>
<Drawer.Screen name="Home" component={Home} />
<Drawer.Screen name="Projects" component={Projects}/>
<Drawer.Screen name="Profile" component={Profile} />
<Drawer.Screen name="Tasks" component={Tasks} />
</Drawer.Navigator>
</Provider >
);
}
function Navigation() {
const authCtx = useContext(AuthContext);
return (
<NavigationContainer>
{!authCtx.isAuthenticated && <AuthStack />}
{authCtx.isAuthenticated && <AuthenticatedStack />}
</NavigationContainer>
);
}
function Root() {
const [isTryingLogin, setIsTryingLogin] = useState(true);
const authCtx = useContext(AuthContext);
useEffect(() => {
async function fetchUser() {
const email = await AsyncStorage.getItem('email');
const id = await AsyncStorage.getItem('userId');
if (email && id) {
console.log("app js "+ email + " "+ id);
authCtx.authenticate({ email, id});
}
console.log("app js "+ email + " "+ id);
setIsTryingLogin(false);
}
fetchUser();
}, []);
if (isTryingLogin) {
return <AppLoading />;
}
return <Navigation />;
}
export default function App() {
return (
<>
<StatusBar style="light" />
<AuthContextProvider>
<Root />
</AuthContextProvider>
</>
);
}