Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
inventory-frontend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Jira
Jira
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
coding-brunch-hh
inventory-frontend
Commits
ab565227
Commit
ab565227
authored
Aug 08, 2018
by
Martin Fahl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
uses axios
parent
fa426a4a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
21 deletions
+3
-21
src/actions/index.js
src/actions/index.js
+3
-21
No files found.
src/actions/index.js
View file @
ab565227
...
...
@@ -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
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment