-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.tsx
106 lines (97 loc) · 3.76 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
95
96
97
98
99
100
101
102
103
104
105
106
import "react-native-gesture-handler";
import { useEffect } from "react";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import useFirstLaunch from "./hooks/useFirstLaunch";
import { AppRoutes } from "./constants/AppRoutes";
import { AuthenticationRoutes } from "./constants/AuthenticationRoutes";
import MainNavigator from "./constants/MainNavigator";
import AuthContextProvider from "./store/AuthContext";
import useStart from "./hooks/useStart";
import useAuth from "./hooks/useAuth";
import { AuthContext } from "./store/AuthContext";
import Loading from "./components/Loading";
import Onboard from "./screens/Onboard";
import Login from "./screens/Login";
import Signup from "./screens/Signup";
import InitialStartScreen from "./screens/initialStart";
import Dashboard from "./screens/Dashboard";
import { useContext } from "react";
import AsyncStorage from "@react-native-async-storage/async-storage";
import SingleDocument from "./screens/SingleDocument";
import Jobs from "./screens/Jobs";
import SingleJob from "./screens/SingleJob";
import VerifyOTP from "./screens/OTPVerifier";
import ApplyNow from "./screens/ApplyNow";
const AppStack = createNativeStackNavigator<AppRoutes>();
const AuthenticationStack = createNativeStackNavigator<AuthenticationRoutes>();
const App = () => {
// todo -> Implement the logic during signup and login in the screen to complete the flow smoothly ....
const isFirstLaunch = useFirstLaunch();
// const { isLoggedIn, user } = useStart();
const { token, isLoggedIn } = useContext(AuthContext);
const auth = useAuth();
AsyncStorage.getItem("@token").then((token) => {console.log("TOKEN FROM ASYNC STORAGE: ", token)});
// const login = async () => {
// if (isLoggedIn && user) {
// await auth.login(user);
// }
// };
// useEffect(() => {
// login();
// }, [isLoggedIn, isFirstLaunch, user]);
if (isFirstLaunch === null || isLoggedIn === null) return <Loading />;
const AuthenticationNavigator = () => {
return (
<AuthenticationStack.Navigator
screenOptions={{ headerShown: false }}
initialRouteName={isFirstLaunch ? "Initial" : "Login"}
>
<AuthenticationStack.Screen name="Initial" component={InitialStartScreen} />
<AuthenticationStack.Screen name="Onboard" component={Onboard}/>
<AuthenticationStack.Screen name="Login" component={Login} />
<AuthenticationStack.Screen name="Signup" component={Signup} />
<AuthenticationStack.Screen name="VerifyOTP" component={VerifyOTP} />
{/* <AuthenticationStack.Screen name="Dashboard" component={Dashboard} /> */}
</AuthenticationStack.Navigator>
)
}
return (
<NavigationContainer>
<SafeAreaProvider>
<AppStack.Navigator
screenOptions={{ headerShown: false }}
initialRouteName={isLoggedIn ? "Main" : "Authentication"}
>
<AppStack.Screen
name="Authentication"
component={AuthenticationNavigator}
/>
<AppStack.Screen name="Main"
component={MainNavigator}
/>
<AppStack.Screen name="Single Document"
component={SingleDocument}
/>
<AppStack.Screen name="Jobs"
component={Jobs}
/>
<AppStack.Screen name="Single Job"
component={SingleJob}
/>
<AppStack.Screen name="ApplyNow"
component={ApplyNow}
/>
</AppStack.Navigator>
</SafeAreaProvider>
</NavigationContainer>
);
};
export default function AppWrapper() {
return (
<AuthContextProvider>
<App />
</AuthContextProvider>
)
}