-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
75 lines (68 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
import React, { useState, useEffect } from 'react';
import { Platform, View, Text } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { Provider } from 'react-redux';
import { configureStore } from '@reduxjs/toolkit';
import thunk from 'redux-thunk';
import { auth } from './src/components/config/firebaseConfig'; // Import from the centralized file
import rootReducer from './src/redux/reducers';
import LandingScreen from './src/components/Auth/Landing';
import RegisterScreen from './src/components/Auth/Register';
import LoginScreen from './src/components/Auth/Login';
import MainScreen from './src/components/main/Main';
import AddScreen from './src/components/main/Add';
// Configure Redux store
const store = configureStore({
reducer: rootReducer,
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(thunk),
});
const Stack = createStackNavigator();
export default function App() {
const [loggedIn, setLoggedIn] = useState(false);
const [loaded, setLoaded] = useState(false);
useEffect(() => {
const unsubscribe = auth.onAuthStateChanged((user) => {
console.log('Auth state changed:', user);
setLoggedIn(!!user);
setLoaded(true);
});
return unsubscribe;
}, []);
if (!loaded) {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: '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} />
</Stack.Navigator>
</NavigationContainer>
</Provider>
);
}