-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
77 lines (70 loc) · 2.01 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
import { useEffect, useState } from 'react';
import { Alert } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { observer } from '@legendapp/state/react';
import { store$ } from './utils/Store';
import { supabase } from './utils/Supabase';
import MainNavigator from './navigation/MainNavigator';
import WelcomeScreen from './screens/WelcomeScreen';
const App = observer(function App() {
const [realPassword, setRealPassword] = useState(null);
const [loading, setLoading] = useState(false);
const [online, setOnline] = useState(true);
const enabled = store$.enabled.get();
useEffect(() => {
onRefresh();
}, []);
const onRefresh = async () => {
setLoading(true);
const { data } = await supabase
.from('login')
.select('password, rallye!inner(id)')
.eq('rallye.is_active_rallye', true);
if (data) {
setRealPassword(data[0].password);
setOnline(true);
} else {
setOnline(false);
}
setLoading(false);
};
const handlePasswordSubmit = async (password) => {
if (password === realPassword) {
const { data } = await supabase
.from('rallye')
.select('*')
.eq('is_active_rallye', true);
const rallye = data[0];
if (rallye.end_time) {
rallye.end_time = new Date(rallye.end_time);
}
store$.rallye.set(rallye);
store$.enabled.set(true);
} else {
Alert.alert(
'Falsches Passwort',
'Bitte geben Sie das richtige Passwort ein.'
);
}
};
const handleNoPasswordSubmit = () => {
store$.rallye.set(null);
store$.enabled.set(true);
};
return (
<NavigationContainer>
{enabled ? (
<MainNavigator />
) : (
<WelcomeScreen
onPasswordSubmit={handlePasswordSubmit}
onContinueWithoutRallye={handleNoPasswordSubmit}
networkAvailable={online}
loading={loading}
onRefresh={onRefresh}
/>
)}
</NavigationContainer>
);
});
export default App;