-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApp.js
112 lines (103 loc) · 3.89 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
110
111
112
import { StatusBar } from 'expo-status-bar';
import React, { useEffect, useState, useCallback } from 'react';
import { NativeRouter, Route, Routes } from 'react-router-native';
import { View } from 'react-native';
import * as Localization from 'expo-localization';
import { getConfig, reset } from './data/configApi';
import { lang as LangInterface } from './language/interface';
import ChooseUsername from './pages/ChooseUsername';
import Loading from './components/utils/Loading';
import HomeOrTutorial from './components/utils/HomeOrTutorial';
import SelectionMenu from './pages/SelectionMenu';
import Activities from './pages/Activities';
import Home from './pages/Home';
import Tutorial from './pages/Tutorial';
export default function App() {
const [config, setConfig] = useState();
const [lang, setLang] = useState('fr');
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
// reset();
loadDataCallback();
}, [loadDataCallback]);
useEffect( () => {
let local = Localization.locale?.split('-')[0] || 'fr';
setLang(['en', 'fr'].includes(local) ? local : 'fr');
console.log('- Imported config file -');
}, [config]);
const loadDataCallback = useCallback(async () => {
try {
fetchData();
} catch (err) {
console.error(err);
}
}, []);
const fetchData = async () => {
getConfig().then((resp) => {
setConfig(resp);
setIsLoading(false);
});
};
return (
<View style={{ flex: 1 }}>
<StatusBar hidden={true} />
{isLoading ? (
<Loading
style={{ flex: 1, alignItems: 'center' }}
text={LangInterface[lang]?.GlobalLoading}
/>
) : (
<NativeRouter>
<Routes>
<Route
exact
path="/"
element={
<HomeOrTutorial
hasSeenTutorial={config?.hasSeenTutorial}
lang={lang}
username={config?.username}
setLang={setLang}
/>
}
/>
<Route
exact
path="/tutorial"
element={
<Tutorial
lang={lang}
/>
}
/>
<Route
exact
path="/home"
element={<Home lang={lang} username={config?.username} setLang={setLang} />}
/>
<Route
exact
path="/username"
element={<ChooseUsername lang={lang} username={config?.username} setLang={setLang} />}
/>
<Route
exact
path="/selection"
element={
<SelectionMenu
hasSeenTutorial={config?.hasSeenTutorial}
lang={lang}
username={config?.username}
/>
}
/>
<Route
path="/activities/:id"
element={<Activities />}
/>
</Routes>
</NativeRouter>
)}
</View>
);
}