From 6ef0d3ef41240a3171effce236feee70eafd37c9 Mon Sep 17 00:00:00 2001 From: David Jay Date: Wed, 9 Nov 2016 18:30:01 -0500 Subject: [PATCH] Posting flags correctly and displaying flags when clicked. --- client/coral-embed-stream/src/CommentStream.js | 14 +++++++++----- client/coral-framework/store/actions/items.js | 16 +++++++++------- client/coral-plugin-flags/FlagButton.js | 12 ++++++++---- models/action.js | 3 ++- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/client/coral-embed-stream/src/CommentStream.js b/client/coral-embed-stream/src/CommentStream.js index 3a1acbbc6..11704b4f1 100644 --- a/client/coral-embed-stream/src/CommentStream.js +++ b/client/coral-embed-stream/src/CommentStream.js @@ -51,8 +51,8 @@ const {setLoggedInUser} = authActions setLoggedInUser: (user_id) => { return dispatch(setLoggedInUser(user_id)) }, - postAction: (item, action, user) => { - return dispatch(postAction(item, action, user)) + postAction: (item, action, user, item_type) => { + return dispatch(postAction(item, action, user, item_type)) }, appendItemArray: (item, property, value, addToFront, itemType) => { return dispatch(appendItemArray(item, property, value, addToFront, itemType)) @@ -126,8 +126,10 @@ class CommentStream extends Component {
{ const action = { - type, + action_type, user_id } const options = { method: 'POST', + headers: { + 'Content-Type':'application/json' + }, body: JSON.stringify(action) } - return fetch('/api/v1/comments/' + item_id + '/actions', options) + return fetch('/api/v1/' + item_type + '/' + item_id + '/actions', options) .then( response => { return response.ok ? response.json() : Promise.reject(response.status + ' ' + response.statusText) } ).then((json)=>{ - return json.id + return json }) } } diff --git a/client/coral-plugin-flags/FlagButton.js b/client/coral-plugin-flags/FlagButton.js index 0c5bbcbc5..8ff2c9aeb 100644 --- a/client/coral-plugin-flags/FlagButton.js +++ b/client/coral-plugin-flags/FlagButton.js @@ -2,13 +2,17 @@ import React from 'react' const name='coral-plugin-flags' -const FlagButton = ({flag, item_id, postAction, currentUser, addNotification}) => { - const flagged = flag && flag.includes(currentUser) +const FlagButton = ({flag, id, postAction, addItem, updateItem, addNotification}) => { + const flagged = flag && flag.current_user const onFlagClick = () => { - postAction(item_id, 'flag', currentUser) + postAction(id, 'flag', '123', 'comments') + .then((action) => { + addItem({...action, current_user:true}, 'actions') + updateItem(action.item_id, action.action_type, action.id, 'comments') + }) addNotification('success', 'Thank you for reporting this comment. Our moderation team has been notified and will review it shortly.') - } + return