Commit ab565227 authored by Martin Fahl's avatar Martin Fahl

uses axios

parent fa426a4a
......@@ -58,33 +58,15 @@ export const itemsLoaded = (items) => ({
})
export const getAllItems = () => dispatch => {
fetch('/api/items')
.then(response => response.json())
.then(json => dispatch(itemsLoaded(json)))
Axios.get('/api/items').then((response) => dispatch(itemsLoaded(response.data)))
}
export const addItem = (name, quantity) => dispatch => {
var xmlhttp = new XMLHttpRequest()
xmlhttp.open("POST", "/api/items")
xmlhttp.setRequestHeader("Content-Type", "application/json")
xmlhttp.onreadystatechange = () => {
if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
var json = JSON.parse(xmlhttp.responseText);
dispatch(itemAdded(json.id, json.name, json.quantity))
}
}
xmlhttp.send(JSON.stringify({name, quantity}))
Axios.post('/api/items', {name, quantity}).then((response) => dispatch(itemAdded(response.data.id, response.data.name, response.data.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()
Axios.delete('/api/items/'+id).then(dispatch(itemDeleted(id)))
}
export const updateItem = (id, name, quantity) => dispatch => {
......
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