-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
54 lines (47 loc) · 1.49 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
import { StatusBar } from 'expo-status-bar';
import React, { useState } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import AppLoading from 'expo-app-loading';
import AuthContext from './app/auth/context';
import FlipCardContext from './app/context/flipcard';
import AuthNavigator from './app/navigation/AuthNavigator';
import AppNavigator from './app/navigation/AppNavigator';
import authStorage from './app/auth/storage';
import { FlashcardProvider } from './app/context/flashcard';
type User = {
name: string;
email: string;
};
export default function App() {
const [user, setUser] = useState<User | null>(null);
const [flipped, setFlipped] = useState(false);
const [isReady, setIsReady] = useState(false);
const flipCard = () => {
setFlipped(!flipped);
};
const restoreUser = async () => {
const user = await authStorage.getUser();
if (user) setUser(user);
};
if (!isReady) {
return (
<AppLoading
startAsync={restoreUser}
onFinish={() => setIsReady(true)}
onError={console.warn}
/>
);
}
return (
<NavigationContainer>
<AuthContext.Provider value={{ user, setUser }}>
<FlipCardContext.Provider value={{ flipped, flipCard }}>
<FlashcardProvider>
{user ? <AppNavigator /> : <AuthNavigator />}
</FlashcardProvider>
<StatusBar style="auto" />
</FlipCardContext.Provider>
</AuthContext.Provider>
</NavigationContainer>
);
}