Commit 81a8bc1a authored by Martin Fahl's avatar Martin Fahl

removes code to delete item

parent 88603a69
import * as types from "../constants/ActionTypes"
export const deleteItem = id => ({
type: types.ITEM_DELETED,
id
})
export const updateItem = (id, name, quantity) => ({
type: types.ITEM_UPDATED,
id,
......
......@@ -6,7 +6,7 @@ import DeleteIcon from "@material-ui/icons/Delete"
const increment = (quantity) => quantity + 1
const decrement = (quantity) => quantity > 1 ? quantity - 1 : 0
const Item = ({ id, name, quantity, updateItem, deleteItem }) => (
const Item = ({ id, name, quantity, updateItem }) => (
<ListItem>
<ListItemText>
<Typography id="nameText" variant="subheading">
......@@ -26,7 +26,7 @@ const Item = ({ id, name, quantity, updateItem, deleteItem }) => (
<IconButton id="increment" onClick={() => updateItem(id, name, increment(quantity))} aria-label="Increment">
<Icon color="secondary">arrow_upward</Icon>
</IconButton>
<IconButton id="delete" onClick={() => deleteItem(id)} aria-label="Delete">
<IconButton id="delete" aria-label="Delete">
<DeleteIcon />
</IconButton>
</ListItem>
......
import { connect } from "react-redux"
import Item from "../../components/Item/Item"
import { updateItem, deleteItem } from "../../actions"
import { updateItem } from "../../actions"
import { createSelector } from "reselect"
const getItem = (state, props) => state.items.find(item => item.id === props.id)
......@@ -15,8 +15,7 @@ const mapStateToProps = (state, props) => ({
})
const mapDispatchToProps = dispatch => ({
updateItem: (id, name, quantity) => dispatch(updateItem(id, name, quantity)),
deleteItem: id => dispatch(deleteItem(id))
updateItem: (id, name, quantity) => dispatch(updateItem(id, name, quantity))
})
export default connect(
......
......@@ -18,24 +18,4 @@ describe("items reducer", () => {
{id: "3358", name: "Wine", quantity: 40} ])
})
it("should handle ITEM_ADDED", () => {
expect(
reducer([], {
type: types.ITEM_ADDED,
...item1
})
).toEqual(
[item1]
)
expect(
reducer([item1], {
type: types.ITEM_ADDED,
...item2
})
).toEqual(
[item1, item2]
)
})
})
\ No newline at end of file
......@@ -6,8 +6,6 @@ const INITIAL_STATE = [ {id: "1156", name: "Peanuts", quantity: 4},
const items = (state = INITIAL_STATE, action) => {
switch (action.type) {
case ITEM_DELETED:
return state.filter(item => (item.id !== action.id))
case ITEM_UPDATED:
return state.map(item => (
item.id === action.id ? {...item, name: action.name, quantity: action.quantity } : item
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment