Repository navigation
Expand file tree
/
Copy pathApp.js
More file actions
103 lines (89 loc) · 2.94 KB
/
Copy pathApp.js
File metadata and controls
103 lines (89 loc) · 2.94 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
import { StyleSheet, View } from "react-native";
import { DefaultTheme, NavigationContainer } from "@react-navigation/native";
import { StatusBar } from "expo-status-bar";
import { SafeAreaProvider } from "react-native-safe-area-context";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { Provider, useSelector, useDispatch } from "react-redux";
import store from "./Configure";
import Tabs from "./navigators/Tabs";
import Profile from "./screens/Profile";
import ClubDetails from "./screens/ClubDetails";
import EventDetails from "./screens/EventDetails";
import ClubEvents from "./screens/ClubEvents";
import Edit from "./screens/Edit";
import Colors from "./src/constants/Colors";
import LogIn from "./screens/auth/LogIn";
import SignUp from "./screens/auth/SignUp";
import ForgotPass from "./screens/auth/ForgotPass";
import { useContext, useState, useEffect } from "react";
import * as SecureStore from "expo-secure-store";
import * as actionType from "./API/actionTypes";
const Stack = createNativeStackNavigator();
const MyTheme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
background: Colors.background.base,
},
};
const AppNavigator = () => {
const dispatch = useDispatch();
const isLoggedIn = useSelector((state) => state.auth.authData !== null);
const fetchProfile = () => async (dispatch) => {
try {
const storedProfile = await SecureStore.getItemAsync("profile");
if (storedProfile) {
await dispatch({
type: actionType.AUTH,
data: JSON.parse(storedProfile),
});
}
} catch (error) {
console.error("Error fetching profile:", error);
}
};
useEffect(() => {
dispatch(fetchProfile());
}, [dispatch]);
return (
<NavigationContainer theme={MyTheme}>
<Stack.Navigator
screenOptions={{
headerShown: false,
// gestureEnabled: false,
animation: "none",
}}
>
{!isLoggedIn ? (
<>
<Stack.Screen name="LogIn" component={LogIn} />
<Stack.Screen name="SignUp" component={SignUp} />
<Stack.Screen name="ForgotPassword" component={ForgotPass} />
</>
) : (
<>
<Stack.Screen name="Tabs" component={Tabs} />
<Stack.Screen name="Profile" component={Profile} />
<Stack.Screen name="ClubDetails" component={ClubDetails} />
<Stack.Screen name="ClubEvents" component={ClubEvents} />
<Stack.Screen name="EventDetails" component={EventDetails} />
<Stack.Screen name="Edit" component={Edit} />
</>
)}
</Stack.Navigator>
</NavigationContainer>
);
};
export default function App() {
return (
<Provider store={store}>
<SafeAreaProvider>
<StatusBar style="light" />
<>
<AppNavigator />
</>
</SafeAreaProvider>
</Provider>
);
}
const styles = StyleSheet.create({});