-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
107 lines (100 loc) · 3.09 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
// import { StatusBar } from "expo-status-bar";
import React, { useState, useEffect } from "react";
import { View, Text } from "react-native";
import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";
import firebase from "firebase/app";
import FIREBASE_CONFIG from "./apikey";
import { Provider } from "react-redux";
import { createStore, applyMiddleware } from "redux";
import rootReducer from "./redux/reducers";
import thunk from "redux-thunk";
const store = createStore(rootReducer, applyMiddleware(thunk));
import LandingScreen from "./components/auth/Landing";
import RegisterScreen from "./components/auth/Register";
import LoginScreen from "./components/auth/Login";
import MainScreen from "./components/Main";
import AddScreen from "./components/Main/Add";
import SaveScreen from "./components/Main/Save";
import CategoryScreen from "./components/Main/Category";
import PostScreen from "./components/Main/Posts";
const firebaseConfig = FIREBASE_CONFIG;
!firebase.apps.length ? firebase.initializeApp(firebaseConfig) : firebase.app();
const Stack = createStackNavigator();
export default function App() {
const [loaded, setLoaded] = useState(false);
const [loggedIn, setLoggedIn] = useState(false);
useEffect(() => {
firebase.auth().onAuthStateChanged((user) => {
if (!user) {
setLoggedIn(false);
setLoaded(true);
} else {
setLoggedIn(true);
setLoaded(true);
}
});
}, []);
if (!loaded) {
return (
<View style={{ flex: 1, justifyContent: "center" }}>
<Text>Loading</Text>
</View>
);
}
if (!loggedIn) {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Landing">
<Stack.Screen
name="Landing"
component={LandingScreen}
options={{ headerShown: false }}
/>
<Stack.Screen name="Register" component={RegisterScreen} />
<Stack.Screen name="Login" component={LoginScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
return (
<Provider store={store}>
<NavigationContainer>
<Stack.Navigator initialRouteName="Main">
<Stack.Screen
name="Main"
component={MainScreen}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Add"
component={AddScreen}
navigation={Stack}
options={{ headerBackTitle: false }}
/>
<Stack.Screen
name="Save"
component={SaveScreen}
options={{
headerBackTitle: false,
}}
/>
<Stack.Screen
name="Posts"
component={PostScreen}
options={{
headerBackTitle: false,
}}
/>
<Stack.Screen
name="Category"
component={CategoryScreen}
options={{
headerBackTitle: false,
}}
/>
</Stack.Navigator>
</NavigationContainer>
</Provider>
);
}