Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Mimimum/Maximum Quantity #82

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"android": {
"package": "com.devinim.shoppinglist",
"versionCode": 3
"versionCode": 4
},
"androidStatusBar": {
"barStyle": "light-content",
Expand Down
47 changes: 43 additions & 4 deletions src/redux/actions/shoppingListActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,49 @@ const getShoppingListFBSnapshot = async house => {
return snapshot.val();
};

export const pushShoppinglistEventToFirestore = event => (
dispatch,
getStore
) => {
export const onIncrement = item => (dispatch, getStore) => {
if (item.quantity < 100) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not going to work for units like 500 grams

pushShoppinglistEventToFirestore({
type: SHOPPING_LIST.INCREMENT_QUANTITY,
payload: item
})(dispatch, getStore);
}
};

export const onDecrement = item => (dispatch, getStore) => {
if (item.quantity > 1) {
pushShoppinglistEventToFirestore({
type: SHOPPING_LIST.DECREMENT_QUANTITY,
payload: item
})(dispatch, getStore);
}
};

export const onToggle = item => (dispatch, getStore) => {
pushShoppinglistEventToFirestore({
type: SHOPPING_LIST.EDIT_ITEM,
payload: { ...item, done: !item.done }
})(dispatch, getStore);
};

export const onSaveItem = item => (dispatch, getStore) => {
const type = item.id ? SHOPPING_LIST.EDIT_ITEM : SHOPPING_LIST.ADD_ITEM;
pushShoppinglistEventToFirestore({
type,
payload: item
})(dispatch, getStore);
};

export const onRemoveItem = item => (dispatch, getStore) => {
pushShoppinglistEventToFirestore({
type: SHOPPING_LIST.REMOVE_ITEM,
payload: {
id: item.id
}
})(dispatch, getStore);
};

const pushShoppinglistEventToFirestore = event => (dispatch, getStore) => {
const { sessionStore } = getStore();
const { house, user } = sessionStore;

Expand Down
58 changes: 12 additions & 46 deletions src/screens/ListScreen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import Header from './shopping-list/Header';

import {
loadShoppinglistEventsFromFirestore,
pushShoppinglistEventToFirestore,
onIncrement,
onDecrement,
onRemoveItem,
onToggle,
generateSnaphostInFirestore,
signOut
} from '../../redux/actions';

import { SHOPPING_LIST } from '../../redux/types';

class ListScreen extends React.Component {
static navigationOptions = () => ({
header: null
Expand All @@ -39,44 +40,6 @@ class ListScreen extends React.Component {
});
}

onIncrement = item => {
this.props.pushShoppinglistEventToFirestore({
type: SHOPPING_LIST.INCREMENT_QUANTITY,
payload: item
});
};

onDecrement = item => {
this.props.pushShoppinglistEventToFirestore({
type: SHOPPING_LIST.DECREMENT_QUANTITY,
payload: item
});
};

onToggle = item => {
this.props.pushShoppinglistEventToFirestore({
type: SHOPPING_LIST.EDIT_ITEM,
payload: { ...item, done: !item.done }
});
};

onSaveItem = item => {
const type = item.id ? SHOPPING_LIST.EDIT_ITEM : SHOPPING_LIST.ADD_ITEM;
this.props.pushShoppinglistEventToFirestore({
type,
payload: item
});
};

onRemoveItem = item => {
this.props.pushShoppinglistEventToFirestore({
type: SHOPPING_LIST.REMOVE_ITEM,
payload: {
id: item.id
}
});
};

render() {
return (
<View style={styles.container}>
Expand All @@ -88,10 +51,10 @@ class ListScreen extends React.Component {
<View style={styles.innerContainer}>
<ShoppingList
itemProps={{
onIncrement: this.onIncrement,
onDecrement: this.onDecrement,
onRemoveItem: this.onRemoveItem,
onToggle: this.onToggle
onIncrement: this.props.onIncrement,
onDecrement: this.props.onDecrement,
onRemoveItem: this.props.onRemoveItem,
onToggle: this.props.onToggle
}}
onSaveItem={this.onSaveItem}
list={this.props.shoppingList}
Expand Down Expand Up @@ -124,7 +87,10 @@ export default connect(
mapStateToProps,
{
loadShoppinglistEventsFromFirestore,
pushShoppinglistEventToFirestore,
onIncrement,
onDecrement,
onRemoveItem,
onToggle,
generateSnaphostInFirestore,
signOut
}
Expand Down