-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
110 lines (101 loc) · 4.22 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
108
109
110
import 'react-native-gesture-handler';
import * as React from 'react';
import {Provider, connect} from 'react-redux';
import {NavigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import store from "./src/store";
import HomeScreen from "./src/screens/HomeScreen";
import {createBottomTabNavigator} from '@react-navigation/bottom-tabs';
import ScannerScreen from "./src/screens/ScannerScreen";
import ShoppingScreen from "./src/screens/ShoppingScreen";
import ShoppingListScreen from "./src/screens/ShoppingListScreen";
import {Button, Icon} from "react-native-elements";
import PayScreen from "./src/screens/PayScreen";
import LoginScreen from "./src/screens/LoginScreen";
import SignUpScreen from "./src/screens/SignUpScreen";
import {authentication} from "./src/reducers/authReducer";
import {strings} from "./src/locales/i18n";
import CheckoutScreen from "./src/screens/CheckoutScreen";
import UserProfileScreen from "./src/screens/UserProfileScreen";
import {Alert} from "react-native";
import { MenuProvider } from 'react-native-popup-menu';
import {
Menu,
MenuOptions,
MenuOption,
MenuTrigger,
} from 'react-native-popup-menu';
// Connect the screens to Redux
let HomeContainer = connect(state => ({auth: state.authentication}))(HomeScreen);
let UserProfileContainer = connect(state => ({jwt: state.authentication.jwt, userBio: state.userBio}))(UserProfileScreen);
let LoginContainer = connect(state => ({auth: state.authentication}))(LoginScreen);
let SignUpContainer = connect(state => ({auth: state.registration}))(SignUpScreen);
// Create our stack navigator
let RootStack = createStackNavigator();
const Tab = createBottomTabNavigator();
let TrolleyContainer = connect(state => ({trolley: state.trolley, jwt: state.authentication.jwt}))(ShoppingScreen);
let CheckoutContainer = connect(state => ({trolley: state.trolley, jwt: state.authentication.jwt}))(CheckoutScreen);
let ShoppingListContainer = connect(state => ({shoppingList: state.shoppingList, jwt: state.authentication.jwt}))(ShoppingListScreen);
let PayContainer = connect(state => ({trolley: state.trolley, jwt: state.authentication.jwt}))(PayScreen);
let ScannerContainer = connect(state => ({trolley: state.trolley, jwt: state.authentication.jwt}))(ScannerScreen);
const deleteTrolley = () =>
Alert.alert(
"Delete shopping cart?",
"Do you like to delete shopping cart?",
[
{
text: "Cancel",
onPress: () => console.log("Cancel Pressed"),
style: "cancel"
},
{ text: "OK", onPress: () => console.log("OK Pressed") }
],
{ cancelable: false }
);
function InitComponent ({auth, dispatch, navigation}) {
return (
<NavigationContainer>
<RootStack.Navigator>
{auth.loggedIn ? (
<>
<RootStack.Screen name="Home" component={HomeContainer}/>
<RootStack.Screen name="Shopping" component={TrolleyContainer}/>
<RootStack.Screen name="ScannerScreen" component={ScannerContainer}/>
<RootStack.Screen name="Checkout" component={CheckoutContainer} options={{
headerRight: () => (
<MenuProvider>
<Menu>
<MenuTrigger text='edit' />
<MenuOptions>
<MenuOption onSelect={deleteTrolley}/>
</MenuOptions>
</Menu>
</MenuProvider>
),
headerRightContainerStyle: {paddingRight: 5}
}}/>
<RootStack.Screen name="UserProfile" component={UserProfileContainer}/>
<RootStack.Screen
name="PayScreen"
component={PayContainer}
/>
</>
) : (
<>
<RootStack.Screen name="Login" component={LoginContainer}/>
<RootStack.Screen name="SignUp" component={SignUpContainer}/>
</>
)}
</RootStack.Navigator>
</NavigationContainer>
);
}
const AppWithNavigationState = connect(state => ({auth: state.authentication}))(InitComponent)
// Render the app container component with the provider around it
export default function App() {
return (
<Provider store={store}>
<AppWithNavigationState />
</Provider>
);
}