-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
117 lines (104 loc) · 5.87 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
113
114
115
116
117
import 'react-native-gesture-handler';
import { StyleSheet, Text, View } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";
import { useEffect, useState } from "react";
import HomeScreens from "./src/screens/HomeScreens";
import LoginScreen from "./src/screens/LoginScreen";
import ChatScreen from "./src/screens/ChatScreen";
import ProfileUser from "./src/screens/ProfileUser";
import SignupScreen from "./src/screens/SignupScreen";
import NotiScreen from "./src/screens/NotiScreen";
import EditField from "./src/components/Profile/EditField";
import LoadStories from "./src/components/Home/LoadStories";
import ChatWindows from "./src/components/Chat/ChatWindows";
import { getAllIdUserLocal, deleteDataUserLocal, updateAccessTokenAsync, getDataUserLocal } from './src/util'
import Setting from "./src/components/Profile/Setting";
import ChangePassword from "./src/components/Profile/ChangePassword";
import NewPost from "./src/screens/NewPost";
import NewStory from "./src/screens/NewStory";
import SearchScreen from "./src/screens/SearchScreen";
import SettingChat from "./src/components/Chat/SettingChat";
import ForgotPassScreen from "./src/screens/FillEmailScreen";
import VerifyScreen from "./src/screens/VerifyScreen";
import NewPassScreen from "./src/screens/FillPasswordScreen";
import ListFriend from "./src/screens/ListFriend";
import ListPost from "./src/screens/ListPost";
import SettingGroupChat from "./src/components/Chat/SettingGroup";
import BuyPremium from "./src/screens/BuyPremium";
import GenderAndPhone from "./src/components/Profile/GenderAndPhone";
import ContactUs from "./src/components/Profile/ContactUs";
const Stack = createStackNavigator();
export default function App() {
const [loading, setLoading] = useState(true);
const [isLoggedIn, setIsLoggedIn] = useState(false);
useEffect(() => {
// Function to check user login status
const checkLoginStatus = async () => {
try {
const keys = await getAllIdUserLocal();
if (keys.length == 0) {
setIsLoggedIn(false);
return;
}
const dataLocal = await getDataUserLocal(keys[keys.length - 1]);
const dataAsync = await updateAccessTokenAsync(dataLocal.id, dataLocal.refreshToken)
if ("errors" in dataAsync) {
await deleteDataUserLocal(keys[keys.length - 1]);
setIsLoggedIn(false);
return
}
setIsLoggedIn(true);
} catch (error) {
console.error("Error checking user login status:", error);
} finally {
setLoading(false); // Set loading to false after checking is done
}
};
checkLoginStatus();
}, []);
if (loading) {
return (
<View style={styles.container}>
<Text>Loading...</Text>
</View>
);
}
return (
<NavigationContainer>
<Stack.Navigator initialRouteName={isLoggedIn ? "main" : "Login"}>
<Stack.Screen key="main" options={{ headerShown: false }} name="main" component={HomeScreens} />
<Stack.Screen key="chat" options={{ headerShown: false }} name="chat" component={ChatScreen} />
<Stack.Screen key="noti" options={{ headerShown: false }} name="noti" component={NotiScreen} />
<Stack.Screen key="Login" options={{ headerShown: false }} name="Login" component={LoginScreen} />
<Stack.Screen key="Signup" options={{ headerShown: false }} name="Signup" component={SignupScreen} />
<Stack.Screen key="Profile" options={{ headerShown: false }} name="Profile" component={ProfileUser} />
<Stack.Screen key="editField" options={{ headerShown: false }} name="editField" component={EditField} />
<Stack.Screen key="loadStory" options={{headerShown: false}} name="loadStory" component={LoadStories} />
<Stack.Screen key="chatwindow" options={{headerShown: false}} name="chatwindow" component={ChatWindows} />
<Stack.Screen key="setting" options={{headerShown: false}} name="setting" component={Setting} />
<Stack.Screen key="changepassword" options={{headerShown: false}} name="changepassword" component={ChangePassword} />
<Stack.Screen key="newpost" options={{headerShown: false}} name="newpost" component={NewPost} />
<Stack.Screen key="newstory" options={{headerShown: false}} name="newstory" component={NewStory} />
<Stack.Screen key="search" options={{headerShown: false}} name="search" component={SearchScreen} />
<Stack.Screen key="settingChat" options={{headerShown: false}} name="settingChat" component={SettingChat} />
<Stack.Screen key="fillEmail" options={{headerShown: false}} name="fillEmail" component={ForgotPassScreen} />
<Stack.Screen key="verify" options={{headerShown: false}} name="verify" component={VerifyScreen} />
<Stack.Screen key="fillPass" options={{headerShown: false}} name="fillPass" component={NewPassScreen} />
<Stack.Screen key="settingGroupChat" options={{headerShown: false}} name="settingGroupChat" component={SettingGroupChat} />
<Stack.Screen key="listFriend" options={{headerShown: false}} name="listFriend" component={ListFriend} />
<Stack.Screen key="listPost" options={{headerShown: false}} name="listPost" component={ListPost} />
{/* <Stack.Screen key="buyPremium" options={{headerShown: false}} name="buyPremium" component={BuyPremium} /> */}
<Stack.Screen key="genderAndPhone" options={{headerShown: false}} name="genderAndPhone" component={GenderAndPhone} />
<Stack.Screen key="contactUs" options={{headerShown: false}} name="contactUs" component={ContactUs} />
</Stack.Navigator>
</NavigationContainer>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
},
});