-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.js
More file actions
114 lines (108 loc) · 3.43 KB
/
Main.js
File metadata and controls
114 lines (108 loc) · 3.43 KB
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
113
114
import React, { useEffect, useState } from "react";
import { NavigationContainer, DarkTheme } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";
import { useDispatch, useSelector } from "react-redux";
import Tabs from "./navigation/Tabs";
import SignIn from "./screens/Login/SignIn";
import SignUp from "./screens/Login/SignUp";
import CompanionPage from "./screens/companionPage";
import Settings from "./screens/Settings";
import { getCompanions, getEvents } from "./redux/reducers/companions";
import * as SecureStore from "expo-secure-store";
import LottieView from "lottie-react-native";
import AddNewCompanion from "./screens/Add/addNewCompanion";
import AddNewReminder from "./screens/Add/addNewReminder";
import { View, Text, StyleSheet } from "react-native";
const Stack = createStackNavigator();
export default function Main() {
const dispatch = useDispatch();
const { users, error, user, token, loading } = useSelector(
(state) => state.users
);
const [tokenID, setTokenID] = useState(null);
useEffect(() => {
let cleanup = false;
const getToken = async () => {
//await SecureStore.deleteItemAsync("token");
let token1 = await SecureStore.getItemAsync("token");
if (!cleanup) {
setTokenID(token1);
token1 = null;
if (tokenID) {
dispatch(getCompanions(tokenID));
dispatch(getEvents(tokenID));
}
}
};
getToken();
return () => (cleanup = true);
}, [token, tokenID]);
if (loading) {
return (
<View style={[StyleSheet.absoluteFillObject, styles.container]}>
<LottieView source={require("./95967-loader.json")} autoPlay loop />
</View>
);
}
if (!tokenID) {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="SignIn">
<Stack.Screen
name="SignIn"
component={SignIn}
options={{ headerShown: false }}
/>
<Stack.Screen
name="SignUp"
component={SignUp}
options={{ headerShown: false }}
/>
</Stack.Navigator>
</NavigationContainer>
);
} else {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Landing">
<Stack.Screen
name="Landing"
component={Tabs}
options={{ headerShown: false }}
initialParams={{ tokenID: tokenID }}
/>
<Stack.Screen
name="CompanionOverview"
component={CompanionPage}
initialParams={{ tokenID: tokenID }}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Settings"
component={Settings}
options={{ headerShown: false }}
/>
<Stack.Screen
name="AddNewCompanion"
component={AddNewCompanion}
options={{ headerShown: false }}
/>
<Stack.Screen
name="AddNewReminder"
component={AddNewReminder}
options={{ headerShown: false }}
/>
</Stack.Navigator>
</NavigationContainer>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
zIndex: 1,
justifyContent: "center",
backgroundColor: "rgba(0,0,0,0.3)",
},
});