-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.js
87 lines (63 loc) · 2.14 KB
/
Main.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
import React, {useEffect} from 'react'
//redux
import { useSelector, useDispatch } from 'react-redux';
import { View, Text } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import firebase from 'firebase/app';
//screens
import { AuthStackNavigator } from './navigators/AuthStackNavigator';
import MainStackNavigator from './navigators/MainStackNavigator';
import { selectUserEmail, selectUserUid, setActiveUser } from './features/user/userSlice';
import CreateProfileScreen from './screens/Profile/CreateProfileScreen';
import { selectProfileName } from './features/profile/profileSlice';
import { showProfile } from './features/profile/profileSlice';
const RootStack = createStackNavigator();
const Main = () => {
const dispatch = useDispatch();
const userUid = useSelector(selectUserUid)
const profileNmae = useSelector(selectProfileName)
const onAuthStateChanged = (user) => {
if(!user==null){
dispatch(
setActiveUser({
email: user.email,
uid: user.uid
})
)
}
}
useEffect(() =>{
console.log("INSIDE MAIN")
const subscriber = firebase.auth().onAuthStateChanged(onAuthStateChanged);
if(userUid){
dispatch(
showProfile(userUid)
)
}
console.log(profileNmae)
return subscriber; // unsubscribe on unmount
})
if(!userUid){
return (
<NavigationContainer>
<RootStack.Navigator screenOptions={{
headerShown: false,
}}>
<RootStack.Screen name={'AuthStack'} component={AuthStackNavigator}/>
</RootStack.Navigator>
</NavigationContainer>
)
}else{
if(!profileNmae){
return(
<CreateProfileScreen/>
)
}else{
return(
<MainStackNavigator/>
)
}
}
}
export default Main