-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.jsx
95 lines (82 loc) · 3.57 KB
/
App.jsx
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { registerRootComponent } from 'expo';
import { useEffect, useState, useContext, Suspense } from 'react';
import { View, Text, Button, ActivityIndicator, Platform } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import Styling from './src/styles.js';
import { UserContext } from "./src/contexts.js";
import { Icon } from '@rneui/themed';
import Ionicons from '@expo/vector-icons/Ionicons';
import { NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
const Tab = createBottomTabNavigator();
import Auth from './src/auth.jsx';
import Profile from './src/profile.jsx';
import Main from './src/main.jsx';
import Load from './components/load.jsx';
import { RelayEnvironmentProvider } from 'react-relay/hooks';
import { buildGQL } from "./src/utils/dispatch.js";
function App() {
// null: not set; False: not loaded; value: api key
const [apiKey, setApiKey] = useState(false);
const [gql, setGql] = useState(null);
useEffect(() => {
(async () => {
const key = await AsyncStorage.getItem('api-key');
setApiKey(key);
})();
}, []);
useEffect(() => {
(async () => {
setGql(apiKey ? buildGQL(apiKey) : null);
})();
}, [apiKey]);
return (
<UserContext.Provider value={{
key: apiKey,
setKey: setApiKey,
gql,
logout: async () => {
await AsyncStorage.removeItem("api-key");
setApiKey(null);
}}}
>
{
(apiKey && gql) ?
<NavigationContainer>
<Tab.Navigator
sceneContainerStyle={{ overflow: 'visible' }}
cardStyle={{ backgroundColor: 'transparent' }}>
<Tab.Screen name="Home"
options={{
tabBarIcon: ({ focused, color, size }) => (
<Ionicons name={focused ? "home" : "home-outline"} size={size} color={color}/>
),
headerShown: false
}}
>
{() => (
<RelayEnvironmentProvider environment={gql}>
<Suspense fallback={<Load/>}>
<Main />
</Suspense>
</RelayEnvironmentProvider>
)}
</Tab.Screen>
<Tab.Screen
name="Settings"
component={Profile}
options={{ tabBarIcon: ({ focused, color, size }) => (
<Ionicons name="cog" size={size} color={color}/>
)}}
/>
</Tab.Navigator>
</NavigationContainer>
: ((apiKey == null) ?
<Auth setKey={setApiKey} /> :
<Load />
)
}
</UserContext.Provider>
);
}
export default registerRootComponent(App);