forked from TrustUp-app/TrustUp-Frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
64 lines (56 loc) · 1.76 KB
/
Copy pathApp.tsx
File metadata and controls
64 lines (56 loc) · 1.76 KB
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
import { useCallback, useState } from 'react';
import { View, ActivityIndicator, StatusBar } from 'react-native';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import InvestScreen from 'components/pages/InvestScreen';
import SignInScreen from 'components/pages/SignIn';
import CreateAccountScreen from 'components/pages/CreateAccountScreen';
import { MainLayout } from 'components/shared/MainLayout';
import { AuthProvider, useAuth } from 'context/auth.context';
import './global.css';
const colors = require('./theme/colors.json');
type AuthScreen = 'sign-in' | 'create-account';
function AppContent() {
const { user, token, isLoading, signOut } = useAuth();
const [authScreen, setAuthScreen] = useState<AuthScreen>('sign-in');
const handleSignOut = useCallback(() => {
void signOut();
}, [signOut]);
if (isLoading) {
return (
<View
style={{
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: colors.background,
}}>
<ActivityIndicator size="large" color={colors.cta} />
</View>
);
}
if (!token || !user) {
return authScreen === 'sign-in' ? (
<SignInScreen onNavigateToCreateAccount={() => setAuthScreen('create-account')} />
) : (
<CreateAccountScreen
onBack={() => setAuthScreen('sign-in')}
onSuccess={() => setAuthScreen('sign-in')}
/>
);
}
return (
<MainLayout onSignOut={handleSignOut}>
<InvestScreen />
</MainLayout>
);
}
export default function App() {
return (
<SafeAreaProvider>
<StatusBar barStyle="dark-content" backgroundColor="#FFFFFF" translucent={false} />
<AuthProvider>
<AppContent />
</AuthProvider>
</SafeAreaProvider>
);
}