-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
70 lines (55 loc) · 1.84 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
import React, { useEffect } from 'react';
import { LogBox, I18nManager, StatusBar } from 'react-native';
import { AppColor } from './components';
import { NavigationContainer } from '@react-navigation/native';
import NavigationTheme from './navigation/NavigationTheme';
import HomeNavigator from './navigation/AppNavigator';
import AuthNavigator from './navigation/AuthNavigator';
import { useSelector, useDispatch } from 'react-redux';
import { setUser, setUserStatus, setUserLastSeen, FetchUserData, FetchContacts } from './redux/actions';
import * as AuthStorage from "./auth/AuthStorage";
import RNBootSplash from "react-native-bootsplash";
LogBox.ignoreAllLogs();
// App
const App = () => {
const dispatch = useDispatch();
const user = useSelector(state => state.auth.user);
const contactsActive = useSelector(state => state.auth.contactsActive);
useEffect(() => {
const init = async () => {
try {
I18nManager.allowRTL(false);
dispatch(FetchUserData());
dispatch(setUserStatus());
dispatch(setUserLastSeen());
restoreToken();
}
catch (error) {
console.log('App error :', error);
}
};
init().finally(async () => {
await RNBootSplash.hide({ fade: true });
console.log("Bootsplash has been hidden successfully");
});
}, []);
const restoreToken = async () => {
const token = await AuthStorage.getToken();
if (!token) console.log(" Token is null.");
if (token) {
dispatch(FetchContacts());
}
dispatch(setUser(token));
console.log(" Token restored.");
}
return (
<NavigationContainer theme={NavigationTheme} >
<StatusBar
backgroundColor={AppColor.SLightColor}
barStyle="light-content"
/>
{ user ? <HomeNavigator /> : <AuthNavigator />}
</NavigationContainer>
);
};
export default App;