diff --git a/src/Route.tsx b/src/Route.tsx new file mode 100644 index 0000000..fb789be --- /dev/null +++ b/src/Route.tsx @@ -0,0 +1,94 @@ +import { createContext, useContext, useEffect, useState } from 'react'; +import { View, ActivityIndicator } from 'react-native'; + +/* ---------- AUTH SCREENS ---------- */ +import { Login } from './auth/Login'; +/* ---------- APP SCREENS ---------- */ +import Home from './Screen/Home'; +const AuthStack = createNativeStackNavigator(); +const MainStack = createNativeStackNavigator(); +type AuthContextType = { + isLoggedIn: boolean; + setIsLoggedIn: (value: boolean) => void; +}; + + +const AuthContext = createContext(undefined); + +export const useAuth = () => { + const context = useContext(AuthContext); + if (!context) { + throw new Error('useAuth must be used within AuthProvider'); + } + return context; +}; + +function AuthStackNavigator() { + return ( + + + + + + ); +} + +function MainStackNavigator() { + return ( + + + + ); +} + +function RootNavigator() { + const { isLoggedIn } = useAuth(); + return isLoggedIn ? : ; +} + +const Route: React.FC = () => { + const [isLoggedIn, setIsLoggedIn] = useState(false); + const [loading, setLoading] = useState(true); + useEffect(() => { + bootstrap(); + }, []); + + const bootstrap = async () => { + try { + const keys = await AsyncStorage.getAllKeys(); + const stores = await AsyncStorage.multiGet(keys); + + stores.forEach(([key, value]) => { + if (value !== null) { + User[key] = value; + } + }); + + if (User.id) { + setIsLoggedIn(true); + } + } catch (e) { + console.log('Bootstrap error', e); + } finally { + setLoading(false); + } + }; + + + if (loading) { + return ( + + + + ); + } + return ( + + + + + + ); +}; + +export default Route; diff --git a/src/auth/Login.tsx b/src/auth/Login.tsx new file mode 100644 index 0000000..35ae823 --- /dev/null +++ b/src/auth/Login.tsx @@ -0,0 +1,10 @@ +import React from "react"; +import { View } from "react-native"; + +export const Login: React.FC = () => { + return ( + + {/* Implement your login form here */} + + ); +}; \ No newline at end of file