diff --git a/client/coral-embed-stream/src/CommentStream.js b/client/coral-embed-stream/src/CommentStream.js index 3262d32b6..49bff199a 100644 --- a/client/coral-embed-stream/src/CommentStream.js +++ b/client/coral-embed-stream/src/CommentStream.js @@ -268,13 +268,13 @@ const mapStateToProps = state => ({ }); const mapDispatchToProps = (dispatch) => ({ - addItem: (item, itemType) => dispatch(addItem(item, itemType)), + addItem: (args) => dispatch(addItem.apply(args)), updateItem: (id, property, value, itemType) => dispatch(updateItem(id, property, value, itemType)), postItem: (data, type, id) => dispatch(postItem(data, type, id)), getStream: (rootId) => dispatch(getStream(rootId)), addNotification: (type, text) => dispatch(addNotification(type, text)), clearNotification: () => dispatch(clearNotification()), - postAction: (item, action, itemType, field, detail) => dispatch(postAction(item, action, itemType, field, detail)), + postAction: (item, itemType, action) => dispatch(postAction(item, itemType, action)), showSignInDialog: () => dispatch(showSignInDialog()), deleteAction: (item, action, user, itemType) => dispatch(deleteAction(item, action, user, itemType)), appendItemArray: (item, property, value, addToFront, itemType) => dispatch(appendItemArray(item, property, value, addToFront, itemType)), diff --git a/client/coral-framework/actions/items.js b/client/coral-framework/actions/items.js index 0ef3db8eb..e6fa55efa 100644 --- a/client/coral-framework/actions/items.js +++ b/client/coral-framework/actions/items.js @@ -217,14 +217,8 @@ export function postItem (item, type, id) { * */ -export function postAction (item_id, action_type, item_type, field, detail) { +export function postAction (item_id, item_type, action) { return () => { - const action = { - action_type, - field, - detail - }; - return coralApi(`/${item_type}/${item_id}/actions`, {method: 'POST', body: action}); }; } diff --git a/client/coral-plugin-flags/FlagButton.js b/client/coral-plugin-flags/FlagButton.js index a392776cb..36665e71e 100644 --- a/client/coral-plugin-flags/FlagButton.js +++ b/client/coral-plugin-flags/FlagButton.js @@ -34,7 +34,12 @@ export default class FlagButton extends Component { console.log('OtherText', otherText); const updatedDetail = otherText || detail; const item_id = itemType === 'comments' ? id : author_id; - postAction(item_id, 'flag', itemType, field, updatedDetail) + const action = { + action_type: 'flag', + field, + detail: updatedDetail + }; + postAction(item_id, itemType, action) .then((action) => { let id = `${action.action_type}_${action.item_id}`; addItem({id, current_user: action, count: flag ? flag.count + 1 : 1}, 'actions'); diff --git a/client/coral-plugin-likes/LikeButton.js b/client/coral-plugin-likes/LikeButton.js index b3d31fbf4..cfe302768 100644 --- a/client/coral-plugin-likes/LikeButton.js +++ b/client/coral-plugin-likes/LikeButton.js @@ -12,7 +12,10 @@ const LikeButton = ({like, id, postAction, deleteAction, addItem, showSignInDial return; } if (!liked) { - postAction(id, 'like', currentUser.id, 'comments') + const action = { + action_type: 'like' + }; + postAction(id, 'comments', action) .then((action) => { let id = `${action.action_type}_${action.item_id}`; addItem({id, current_user: action, count: like ? like.count + 1 : 1}, 'actions'); diff --git a/tests/client/coral-framework/store/itemActions.spec.js b/tests/client/coral-framework/store/itemActions.spec.js index 8bf65fa33..24b9c78d5 100644 --- a/tests/client/coral-framework/store/itemActions.spec.js +++ b/tests/client/coral-framework/store/itemActions.spec.js @@ -155,7 +155,11 @@ describe('itemActions', () => { describe('postAction', () => { it ('should post an action', () => { fetchMock.post('*', {id: '456'}); - return actions.postAction('abc', 'flag', 'comments', 'Comment smells funny')(store.dispatch) + const action = { + action_type: 'flag', + detail: 'Comment smells funny' + }; + return actions.postAction('abc', 'comments', action)(store.dispatch) .then(response => { expect(fetchMock.calls().matched[0][0]).to.equal('/api/v1/comments/abc/actions'); expect(response).to.deep.equal({id:'456'});