Adding action routes

And fixing a few small issues with item posting.
This commit is contained in:
David Jay
2016-11-03 10:52:16 -07:00
parent f50528e50a
commit 46e6508abe
2 changed files with 18 additions and 15 deletions
+17 -14
View File
@@ -115,9 +115,11 @@ export function getStream (assetId) {
comments: rootComments
}))
Object.keys(childComments).reduce((prev, key) => {
dispatch(updateItem(key, 'children', childComments[key]))
},{})
const keys = Object.keys(childComments)
for (var i=0; i < keys.length; i++ ) {
dispatch(updateItem(keys[i], 'children', childComments[keys[i]]))
}
return (json)
})
}
@@ -169,13 +171,8 @@ export function getItemsArray (ids) {
* The newly put item to the item store
*/
export function postItem (data, type, id) {
export function postItem (item, type, id) {
return (dispatch) => {
let item = {
type,
data,
version: 1
}
if (id) {
item.id = id
}
@@ -214,13 +211,19 @@ export function postItem (data, type, id) {
*
*/
export function postAction (item, action, user) {
export function postAction (id, type, user_id) {
return (dispatch) => {
let options = {
method: 'POST'
const action = {
type,
user_id
}
dispatch(appendItemArray(item, action, user))
return fetch('/v1/action/' + action + '/user/' + user + '/on/item/' + item, options)
const options = {
method: 'POST',
body: JSON.stringify(action)
}
dispatch(appendItemArray(id, type, user_id))
return fetch('api/v1/comments/' + id + '/actions', options)
.then(
response => {
return response.ok ? response.text()
+1 -1
View File
@@ -31,7 +31,7 @@ class CommentBox extends Component {
related = 'comments'
}
updateItem(item_id, 'showReply', false)
postItem(comment, 'comment')
postItem(comment, 'comments')
.then((id) => {
appendItemArray(item_id, related, id)
addNotification('success', 'Your comment has been posted.')