-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
148 lines (137 loc) · 4.63 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import React, {useState, useEffect, useContext} from 'react';
import {Platform, Text, View} from 'react-native';
import GroceryItemSearchScreen from './screens/GroceryItemSearchScreen';
import GroceryListSearchScreen from './screens/GroceryListSearchScreen';
import YourGroceryListScreen from './screens/YourGroceryListScreen';
import {NavigationContainer, DrawerActions} from "@react-navigation/native";
import {navigationRef, isMountedRef} from "./navigation/RootNavigation";
import CurrentStoreContext from "./contexts/CurrentStore";
import GroceryListContext from "./contexts/GroceryList";
import UserContext from "./contexts/User";
import ScannerScreen from "./screens/ScannerScreen";
import {
createDrawerNavigator,
DrawerContentScrollView,
DrawerItemList,
} from "@react-navigation/drawer";
import {Notifications} from 'expo';
import * as Permissions from 'expo-permissions';
import * as SecureStore from 'expo-secure-store';
import RoleSelectionScreen from "./screens/RoleSelectionScreen";
const Drawer = createDrawerNavigator();
function DrawerContent(props) {
const {user, setUser} = useContext(UserContext);
return (
<DrawerContentScrollView {...props}>
<View style={{flex: 1, padding: 15}}>
{user ?
<>
<Text style={{
fontWeight: "bold",
fontSize: 25
}}>{user.firstName + ' ' + user.lastName}</Text>
<Text>{user.email}</Text>
<Text>{user.phone}</Text>
<Text>Role: {user.role}</Text>
</> :
<Text style={{
fontWeight: 'bold',
fontSize: 20
}}>No Role Selected</Text>
}
</View>
<DrawerItemList {...props}/>
</DrawerContentScrollView>
);
}
export default function App() {
const [currentStore, setCurrentStore] = useState({name: "Walmart", id: 0});
const [groceryList, setGroceryList] = useState({});
const [user, setUser] = useState({
role: 'Worker',
phoneNumber: '4161324634',
email: '[email protected]',
firstName: 'John',
lastName: 'Doe'
});
useEffect(() => {
(async() => {
if (Platform.OS === 'android') {
await Notifications.createChannelAndroidAsync('notifications', {
name: 'Notifications',
vibrate: [250],
sound: true,
});
await Notifications.createChannelAndroidAsync('activated', {
name: 'Activated',
});
}
})();
}, []);
useEffect(() => {
(async() => {
const pushToken = await SecureStore.getItemAsync('pushToken');
if (pushToken) return;
const result = await Permissions.askAsync(Permissions.NOTIFICATIONS);
if (result.status !== 'granted') {
return;
}
let token = await Notifications.getExpoPushTokenAsync();
await SecureStore.setItemAsync('pushToken', token);
})();
}, []);
React.useEffect(() => {
isMountedRef.current = true;
return () => {isMountedRef.current = false};
}, []);
return (
<CurrentStoreContext.Provider value={{currentStore, setCurrentStore}}>
<GroceryListContext.Provider value={{groceryList, setGroceryList}}>
<UserContext.Provider value={{user, setUser}}>
<NavigationContainer ref={navigationRef}>
<Drawer.Navigator
initialRouteName="RoleSelection"
drawerContent={props => <DrawerContent {...props}/>}
>
<Drawer.Screen
name="GrocerySearch"
options={{
title: "Groceries"
}}
component={GroceryItemSearchScreen}
/>
<Drawer.Screen
name="GroceryListSearch"
options={{
title: "Grocery Lists"
}}
component={GroceryListSearchScreen}
/>
<Drawer.Screen
name="YourGroceryList"
options={{
title: "Your Grocery List"
}}
component={YourGroceryListScreen}
/>
<Drawer.Screen
name="Scanner"
options={{
title: "Scan QR Code"
}}
component={ScannerScreen}
/>
<Drawer.Screen
name="RoleSelection"
options={{
title: "Change Role"
}}
component={RoleSelectionScreen}
/>
</Drawer.Navigator>
</NavigationContainer>
</UserContext.Provider>
</GroceryListContext.Provider>
</CurrentStoreContext.Provider>
);
}