-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
75 lines (67 loc) · 1.98 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
import {NavigationContainer} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack';
import React, {useEffect, useState} from 'react';
import {ActivityIndicator, StyleSheet, View} from 'react-native';
import Container from './app/components/container';
import {ALTURA_PURPLE} from './app/constants/colors';
import {LAUNCH, MAIN} from './app/constants/screens';
import DatabaseManager from './app/database/manager';
import {subscribeUser} from './app/database/subscription/user';
import {HomeRoute} from './app/navigation';
import {queryUser} from './app/queries/user';
import Launch from './app/screens/launch';
DatabaseManager.init();
const styles = StyleSheet.create({
loader: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});
const Stack = createNativeStackNavigator();
export const App = () => {
const [isLoggedIn, setIsLoggedIn] = useState<boolean>(false);
const [querying, setIsQuerying] = useState<boolean>(true);
useEffect(() => {
const userSubscription = subscribeUser(users => {
console.log('>>> users', {users});
setIsLoggedIn(Boolean(users[0]));
setIsQuerying(false);
});
return () => {
userSubscription?.unsubscribe();
};
}, []);
if (querying) {
return (
<View style={styles.loader}>
<ActivityIndicator size="large" color={ALTURA_PURPLE} />
</View>
);
}
return (
<NavigationContainer>
<Stack.Navigator>
{isLoggedIn ? (
<Stack.Screen
component={HomeRoute}
name={MAIN}
options={{headerShown: false}}
/>
) : (
<Stack.Screen
component={Launch}
name={LAUNCH}
options={{
title: 'Create a PIN',
headerStyle: {
backgroundColor: ALTURA_PURPLE,
},
}}
/>
)}
</Stack.Navigator>
</NavigationContainer>
);
};
export default App;