Skip to content

Commit

Permalink
made changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Leon Si committed Apr 7, 2020
1 parent a81f4fe commit 047c803
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 62 deletions.
20 changes: 8 additions & 12 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,9 @@ import {Notifications} from 'expo';
import * as Permissions from 'expo-permissions';
import * as SecureStore from 'expo-secure-store';
import RoleSelectionScreen from "./screens/RoleSelectionScreen";
import {Overlay} from 'react-native-elements';

const Drawer = createDrawerNavigator();

const userInfo = {
name: "John Doe",
email: "[email protected]",
phone: "(416) 132-4634",
timeout: "00:34",
role: "Worker",
description: "Worker for Walmart"
};

function DrawerContent(props) {
const {user, setUser} = useContext(UserContext);

Expand Down Expand Up @@ -61,7 +51,13 @@ function DrawerContent(props) {
export default function App() {
const [currentStore, setCurrentStore] = useState({name: "Walmart", id: 0});
const [groceryList, setGroceryList] = useState({});
const [user, setUser] = useState(null);
const [user, setUser] = useState({
role: 'Worker',
phoneNumber: '4161324634',
email: '[email protected]',
firstName: 'John',
lastName: 'Doe'
});

useEffect(() => {
(async() => {
Expand All @@ -71,6 +67,7 @@ export default function App() {
vibrate: [250],
sound: true,
});

await Notifications.createChannelAndroidAsync('activated', {
name: 'Activated',
});
Expand Down Expand Up @@ -98,7 +95,6 @@ export default function App() {
if (!id) return;
const response = await fetch(`https://grocerserver.herokuapp.com/users/${id}`);
const result = await response.json();

})();
}, []);

Expand Down
1 change: 0 additions & 1 deletion components/GoBackIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default function GoBackIcon({navigation}) {
type="entypo"
containerStyle={{marginLeft: 15}}
onPress={() => {
console.log(navigation);
navigation.dangerouslyGetParent()?.setOptions({
...StackWrapperScreenOptions,
title: currentStore.name
Expand Down
8 changes: 0 additions & 8 deletions components/GroceryList.js

This file was deleted.

18 changes: 9 additions & 9 deletions screens/GroceryItemOrderScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ export default function GroceryItemScreen({navigation, route}) {

<View style={styles.buttonView}>
<View style={{flexDirection:'row'}}>
<Button
title="Cancel"
titleStyle={styles.buttonTextStyle}
buttonStyle={styles.buttonStyle}
containerStyle={[styles.buttonContainer, {marginLeft: 5}]}
onPress={() => {
navigation.pop();
}}
/>
<Button
title={"Add to Cart"}
titleStyle={styles.buttonTextStyle}
Expand All @@ -80,15 +89,6 @@ export default function GroceryItemScreen({navigation, route}) {
navigation.pop();
}}
/>
<Button
title="Cancel"
titleStyle={styles.buttonTextStyle}
buttonStyle={styles.buttonStyle}
containerStyle={[styles.buttonContainer, {marginLeft: 5}]}
onPress={() => {
navigation.pop();
}}
/>
</View>
</View>
</View>
Expand Down
18 changes: 15 additions & 3 deletions screens/GroceryListSearchScreen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useState, useEffect, useContext} from 'react';
import {FlatList, SafeAreaView, StyleSheet, View} from 'react-native';
import {FlatList, SafeAreaView, StyleSheet, Text, View} from 'react-native';
import StackWrapper from '../navigation/StackWrapper';
import {ListItem, SearchBar} from "react-native-elements";
import GroceryListSummaryScreen from "./GroceryListSummaryScreen";
Expand All @@ -10,6 +10,7 @@ import UserContext from "../contexts/User";

function GroceryListSearch({navigation}) {
const [groceryLists, updateGroceryLists] = useState([]);
const [refreshing, setRefreshing] = useState(false);
const {user} = useContext(UserContext);

useEffect(() => {
Expand All @@ -20,25 +21,29 @@ function GroceryListSearch({navigation}) {

async function updateData() {
const listsUrl = 'https://grocerserver.herokuapp.com/lists';
setRefreshing(true);
const response = await fetch(listsUrl);
const result = await response.json();
setRefreshing(false);
updateGroceryLists(result);
}

return (
<SafeAreaView style={styles.container}>
<FlatList
onRefresh={updateData}
refreshing={refreshing}
data={groceryLists}
horizontal={false}
renderItem={({item: groceryList}) => <ListItem
chevron={true}
title={groceryList.author}
title={`${groceryList.user.firstName} ${groceryList.user.lastName}`}
titleStyle={{fontWeight: 'bold'}}
subtitle={
dateFormat(groceryList.createdAt, "dddd, mmmm dS, yyyy, h:MM:ss TT")
}
onPress={() => {
if (!user) {
if (user.role === 'Worker') {
alert("You need to be a shopper to access this screen.");
return;
}
Expand All @@ -47,6 +52,13 @@ function GroceryListSearch({navigation}) {
/>}
keyExtractor={(groceryList) => groceryList._id.toString()}
contentContainerStyle={styles.listContainer}
ListEmptyComponent={
<View style={{flex: 1, alignItems: 'center'}}>
<Text style={{margin: 20}}>
Sorry, this store doesn't have any active grocery lists.
</Text>
</View>
}
/>
</SafeAreaView>
);
Expand Down
2 changes: 1 addition & 1 deletion screens/GroceryListSummaryScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function GroceryListSummaryScreen({navigation, route}) {
useEffect(() => {
navigation.dangerouslyGetParent()?.setOptions({
headerLeft: () => <GoBackIcon navigation={navigation}/>,
title: groceryList.author
title: `${groceryList.user.firstName} ${groceryList.user.lastName}`
});
}, []);

Expand Down
64 changes: 39 additions & 25 deletions screens/RoleSelectionScreen.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,46 @@
import React, {useEffect, useState, useContext} from 'react';
import {View, Text, StyleSheet} from 'react-native';
import {Button} from 'react-native-elements';
import {Button, Input} from 'react-native-elements';
import StackWrapper from "../navigation/StackWrapper";
import * as SecureStore from 'expo-secure-store';
import UserContext from "../contexts/User";

function RoleSelectionScreen() {
const [pushToken, setPushToken] = useState('');
const {user, setUser} = useContext(UserContext);
const [firstName, setFirstName] = useState('John');
const [lastName, setLastName] = useState('Doe');
const [email, setEmail] = useState('[email protected]');

useEffect(() => {
(async() => {
setPushToken(await SecureStore.getItemAsync('pushToken'));
})();
}, []);
const {user, setUser} = useContext(UserContext);

return (
<View style={styles.container}>
<Text style={styles.notice}>
If you're looking to test role-specific features of our app, you
need to select a role that you wish to test. If you're just looking
for a general concept and overview, you can press the menu in the
top left corner and navigate to all the screens, but keep in mind
that specific features for those screens may not work if you haven't
selected a role.
need to select a role that you wish to test. Keep in mind
that specific features for some screens may not work if you haven't
selected the appropriate role.
</Text>
<Input
containerStyle={styles.input}
label="First Name"
value={firstName}
onChangeText={(text) => setFirstName(text)}
/>
<Input
containerStyle={styles.input}
value={lastName}
onChangeText={(text) => setLastName(text)}
label="Last Name"
/>
<Input
containerStyle={styles.input}
value={email}
onChangeText={(text) => setEmail(text)}
label="Email"
/>
<Button
buttonStyle={styles.button}
title="Become Shopper"
title="Become Shopper/Requestor"
onPress={async () => {
const pushToken = await SecureStore.getItemAsync('pushToken');
const usersUrl = 'https://grocerserver.herokuapp.com/users';
Expand All @@ -39,32 +52,29 @@ function RoleSelectionScreen() {
},
body: JSON.stringify({
phoneNumber: '4161324634',
email: '[email protected]',
firstName: 'John',
lastName: 'Doe',
email,
firstName,
lastName,
role: 'Shopper',
pushToken
})
});
const result = await response.json();
setUser(result);
await SecureStore.setItemAsync('userId', result._id);

}}
/>
<Button
buttonStyle={styles.button}
title="Become Requestor"
onPress={() => {

}}
/>
<Button
buttonStyle={styles.button}
title="Become Worker"
onPress={() => {
setUser(null);
}}
/>
<View style={{flex: -1, alignItems: 'center'}}>
<Text style={{fontWeight: 'bold'}}>Current Role:</Text>
<Text>{user ? "Shopper/Requestor" : "Worker"}</Text>
</View>
</View>
);
}
Expand All @@ -79,8 +89,12 @@ const styles = StyleSheet.create({
notice: {
fontWeight: 'bold',
textAlign: 'center'
},
input: {
marginVertical: 10
}
});

export default StackWrapper(RoleSelectionScreen, {
title: 'Change Role'
});
11 changes: 8 additions & 3 deletions screens/YourGroceryListScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function YourGroceryListScreen() {
title="Submit Grocery List Request"
disabled={Object.keys(groceryList).length === 0}
onPress={async () => {
if (!user) {
if (user.role === 'Worker') {
alert("You need to be a shopper to perform this action.");
return;
}
Expand All @@ -79,8 +79,13 @@ function YourGroceryListScreen() {
}),
});
setLoading(false);
const result = await response.json();

if (response.status === 400) {
alert("Something went wrong while trying to process your order");
return;
}
setGroceryList({});
alert("Your grocery list was sucessfully submitted.");
navigation.navigate("GrocerySearch");
}}
containerStyle={{
width: '80%',
Expand Down

0 comments on commit 047c803

Please sign in to comment.