-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
109 lines (95 loc) · 3.12 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import { createStackNavigator } from '@react-navigation/stack';
import { NavigationContainer } from '@react-navigation/native';
import AuthNavigator from './frontend/navigation/AuthNavigator';
import MainNavigator from './frontend/navigation/MainNavigator';
import AsyncStorage from '@react-native-async-storage/async-storage';
import React, { useState, useEffect } from 'react';
import * as NavigationBar from 'expo-navigation-bar';
// Font imports
import {
useFonts,
Montserrat_100Thin,
Montserrat_200ExtraLight,
Montserrat_300Light,
Montserrat_400Regular,
Montserrat_500Medium,
Montserrat_600SemiBold,
Montserrat_700Bold,
Montserrat_800ExtraBold,
Montserrat_900Black,
} from '@expo-google-fonts/montserrat';
import { UserProvider } from './frontend/contexts/UserContext';
import { CommunityProvider } from './frontend/contexts/CommunityContext';
import { StatsProvider } from './frontend/contexts/StatsContext';
import { GoalsProvider } from './frontend/contexts/GoalsContext';
import { RemindersProvider } from './frontend/contexts/RemindersContext';
import { FoodLogProvider } from './frontend/contexts/FoodLogContext';
import { AwardsProvider } from './frontend/contexts/AwardsContext';
import { getUserCommunities } from './frontend/services/CommunityService';
import { Platform } from 'react-native';
const Stack = createStackNavigator();
/**
* App is the root component of the application.
* It sets up a navigation container with a stack navigator.
* The stack navigator includes the 'Navbar' and 'Settings' screens.
* The 'Navbar' screen is set as the initial screen.
* The headers for both screens are hidden.
*
* @returns {React.Element} The rendered navigation container.
*/
export default function App() {
const [fontsLoaded] = useFonts({
Montserrat_100Thin,
Montserrat_200ExtraLight,
Montserrat_300Light,
Montserrat_400Regular,
Montserrat_500Medium,
Montserrat_600SemiBold,
Montserrat_700Bold,
Montserrat_800ExtraBold,
Montserrat_900Black,
});
const [initialRoute, setInitialRoute] = useState(null);
useEffect(() => {
if (Platform.OS === 'android') {
NavigationBar.setBackgroundColorAsync('#000');
}
}, []);
useEffect(() => {
const checkToken = async () => {
try {
const token = await AsyncStorage.getItem('token');
setInitialRoute(token ? 'Main' : 'Auth');
} catch (error) {
console.log(error);
}
};
checkToken();
getUserCommunities();
}, []);
if (!fontsLoaded || !initialRoute) {
return null;
}
return (
<CommunityProvider>
<UserProvider>
<FoodLogProvider>
<StatsProvider>
<GoalsProvider>
<AwardsProvider>
<RemindersProvider>
<NavigationContainer>
<Stack.Navigator initialRouteName={initialRoute}>
<Stack.Screen name="Auth" component={AuthNavigator} options={{ headerShown: false }} />
<Stack.Screen name="Main" component={MainNavigator} options={{ headerShown: false }} />
</Stack.Navigator>
</NavigationContainer>
</RemindersProvider>
</AwardsProvider>
</GoalsProvider>
</StatsProvider>
</FoodLogProvider>
</UserProvider>
</CommunityProvider>
);
}