This repository has been archived by the owner on Nov 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
51 lines (45 loc) · 1.5 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
import { StatusBar } from 'expo-status-bar';
import { Keyboard, TouchableWithoutFeedback } from 'react-native';
// upper navigation
import ExpenseContextProvider from './store/expense-context';
import { Navigation } from './infrastructure/navigation';
import { AuthenticationContextProvider } from './services/authentication.context';
import { SafeArea } from './util/safe-area.component';
import { AuthContext, AuthContextProvider } from './store/auth-context';
import { useContext, useEffect, useState } from 'react';
import AsyncStorage from '@react-native-async-storage/async-storage';
import AppLoading from 'expo-app-loading';
import CommunityContextProvider from './store/community-context';
function Root() {
const [isTryingLogin, setIsTryingLogin] = useState(true);
const authCtx = useContext(AuthContext);
useEffect(() => {
async function fetchUser() {
const storedUser = await AsyncStorage.getItem('user');
const parsedStoredUser = JSON.parse(storedUser);
if (parsedStoredUser) {
authCtx.authenticate(parsedStoredUser);
}
setIsTryingLogin(false);
}
fetchUser();
}, []);
if (isTryingLogin) {
<AppLoading />;
}
return <Navigation />;
}
export default function App() {
return (
<>
<StatusBar style="dark" />
<AuthContextProvider>
<ExpenseContextProvider>
<CommunityContextProvider>
<Root />
</CommunityContextProvider>
</ExpenseContextProvider>
</AuthContextProvider>
</>
);
}