Commit e7928c3d authored by Martin Fahl's avatar Martin Fahl

delete now deletes resource on server

parent 3cf2f8cd
// actions
export const ITEM_ADDED = 'ITEM_ADDED';
export const UPDATE_FILTER = 'UPDATE_FILTER';
export const DELETE_ITEM = 'DELETE_ITEM';
export const ITEM_DELETED = 'ITEM_DELETED';
export const INCREMENT = 'INREMENT_ITEM';
export const DECREMENT = 'DECREMENT_ITEM';
export const ITEMS_LOADED = 'ITEMS_LOADED';
......@@ -22,8 +22,8 @@ export const updateFilter = filterTerm => ({
filterTerm: filterTerm
})
export const deleteItem = id => ({
type: DELETE_ITEM,
export const itemDeleted = id => ({
type: ITEM_DELETED,
id
})
......@@ -77,5 +77,15 @@ export const addItem = (name, quantity) => dispatch => {
}
}
xmlhttp.send(JSON.stringify({name, quantity}))
}
export const deleteItem = (id) => dispatch => {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("DELETE", "/api/items/"+id);
xmlhttp.onreadystatechange = () => {
if (xmlhttp.readyState === 4 && xmlhttp.status === 204) {
dispatch(itemDeleted(id))
}
}
xmlhttp.send()
}
\ No newline at end of file
import { DELETE_ITEM, INCREMENT, DECREMENT, ITEMS_LOADED, ITEM_ADDED } from '../actions';
import { ITEM_DELETED, INCREMENT, DECREMENT, ITEMS_LOADED, ITEM_ADDED } from '../actions';
const items = (state = [], action) => {
switch (action.type) {
......@@ -13,8 +13,7 @@ const items = (state = [], action) => {
quantity: action.quantity
}
]
case DELETE_ITEM:
console.log(action.id);
case ITEM_DELETED:
return state.filter(item => (item.id !== action.id))
case INCREMENT:
return state.map(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