-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
94 lines (81 loc) · 2.31 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
import React, { useEffect, useState, useContext } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { Icon, Container, Text } from 'native-base';
//Screen Imports
import LoadingScreen from './screens/LoadingScreen';
//Stack Imports
// import MenuStack from './stacks/MenuStack';
import MainStack from './stacks/MainStack';
// import BottomTabs from './stacks/BottomTabs';
import AuthStack from './stacks/AuthStack';
//Store Imports
import MessageStore from './services/store/messageStore';
import AuthStore from './services/store/authStore';
import EchoStore from './services/store/echoStore';
//Helper Functions Imports
import { isEmpty } from './services/helperFunctions';
import { GetUser, SignOut } from './services/userService';
import * as Linking from 'expo-linking';
const prefix1 = Linking.makeUrl('/');
export default App = () => {
const linking = {
prefixes: [
prefix1,
// prefix2
],
config: {
screens: {
friends: {
screens: {
add: {
path: '/friends/add/:id?',
parse: {
id: (id) => id,
},
stringify: {
id: (id) => id.replace(/^user-/, ''),
},
},
},
},
},
},
};
const [user, setUser] = useState({});
const [isAuthCompleted, setIsAuthCompleted] = useState(false);
const handleAuth = async () => {
if (isEmpty(user)) {
GetUser()
.then((founduser) => {
if (founduser) {
setUser(founduser);
} else {
setUser({ access_token: null });
}
setIsAuthCompleted(true);
})
.catch((error) => console.log('APP handle auth error', error.message));
}
};
useEffect(() => {
handleAuth();
}, [user]);
if (!isAuthCompleted) {
return <LoadingScreen></LoadingScreen>;
} else {
return (
<AuthStore user={[user, setUser]}>
<EchoStore>
<MessageStore>
<NavigationContainer
linking={linking}
fallback={<LoadingScreen></LoadingScreen>}
>
{user.access_token ? <MainStack /> : <AuthStack />}
</NavigationContainer>
</MessageStore>
</EchoStore>
</AuthStore>
);
}
};