-
Notifications
You must be signed in to change notification settings - Fork 0
/
Authorizer.tsx
99 lines (88 loc) · 3.81 KB
/
Authorizer.tsx
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
import { LoginStackParamList, RootStackParamList, WelcomeStackParamList } from './models';
import React, { useEffect } from 'react';
import { StyleSheet, TouchableOpacity, View } from 'react-native';
import { AppLoading } from 'expo';
import { AppState } from './state/store';
import CreateHousehold from './screens/intro/CreateHousehold';
import EditChore from './screens/EditChore';
import EditChores from './screens/EditChores';
import EditRoomates from './screens/EditRoomates';
import InviteRoomates from './screens/intro/InviteRoomates';
import { Ionicons } from '@expo/vector-icons';
import LoginScreen from './screens/LoginScreen';
import { NavigationContainer } from '@react-navigation/native';
import RecordAChore from './screens/RecordAChore';
import Settings from './screens/Settings';
import ViewChores from './screens/intro/ViewChores';
import ViewHousehold from './screens/ViewHousehold';
import { connect } from 'react-redux';
import { createStackNavigator } from '@react-navigation/stack';
import { dispatchLoadCurrentUser } from './state/users/redux';
const RootStack = createStackNavigator<RootStackParamList>();
const WelcomeStack = createStackNavigator<WelcomeStackParamList>();
const LoginStack = createStackNavigator<LoginStackParamList>();
function mapStateToProps(state: AppState) {
return {
isLoadingCurrentUser: state.user.isLoadingCurrentUser,
currentUser: state.user.currentUser,
};
}
const mapDispatchToProps = {
dispatchLoadCurrentUser,
} as {
dispatchLoadCurrentUser: () => void;
};
type IOwnProps = {};
type IProps = IOwnProps & ReturnType<typeof mapStateToProps> & typeof mapDispatchToProps;
function AuthorizerC(props: IProps) {
useEffect(() => {
props.dispatchLoadCurrentUser();
}, []);
if (props.isLoadingCurrentUser) {
return <AppLoading />;
}
if (!props.currentUser?.accessToken) {
return (
<NavigationContainer>
<LoginStack.Navigator initialRouteName="Login">
<LoginStack.Screen name="Login" component={LoginScreen} options={{ title: 'Household' }} />
</LoginStack.Navigator>
</NavigationContainer>
);
}
if (props.currentUser?.showWelcome) {
return (
<NavigationContainer>
<WelcomeStack.Navigator initialRouteName="CreateHousehold">
<WelcomeStack.Screen name="CreateHousehold" component={CreateHousehold} options={{ title: 'Household' }} />
<WelcomeStack.Screen name="InviteRoomates" component={InviteRoomates} options={{ title: 'Household' }} />
<WelcomeStack.Screen name="ViewChores" component={ViewChores} options={{ title: 'Household' }} />
</WelcomeStack.Navigator>
</NavigationContainer>
);
}
return (
<NavigationContainer>
<RootStack.Navigator initialRouteName="ViewHousehold">
<RootStack.Screen
name="ViewHousehold"
component={ViewHousehold}
options={(props) => ({
title: 'Household',
headerRight: () => (
<TouchableOpacity style={{ marginRight: 20 }} onPress={() => props.navigation.navigate('Settings')}>
<Ionicons name="ios-cog" size={32} color="black" />
</TouchableOpacity>
),
})}
/>
<RootStack.Screen name="EditChore" component={EditChore} options={{ title: 'Household' }} />
<RootStack.Screen name="RecordAChore" component={RecordAChore} options={{ title: 'Household' }} />
<RootStack.Screen name="Settings" component={Settings} options={{ title: 'Household' }} />
<RootStack.Screen name="EditChores" component={EditChores} options={{ title: 'Household' }} />
<RootStack.Screen name="EditRoomates" component={EditRoomates} options={{ title: 'Household' }} />
</RootStack.Navigator>
</NavigationContainer>
);
}
export default connect(mapStateToProps, mapDispatchToProps)(AuthorizerC);