From 1a1df1656ff1781b6594c2fd26eed56de30fd1a1 Mon Sep 17 00:00:00 2001 From: David Jay Date: Fri, 18 Nov 2016 23:20:17 -0500 Subject: [PATCH] Posting like and flag with appropriate user_id. --- client/coral-plugin-flags/FlagButton.js | 9 ++++++--- client/coral-plugin-likes/LikeButton.js | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/client/coral-plugin-flags/FlagButton.js b/client/coral-plugin-flags/FlagButton.js index a4869c486..77fe519f9 100644 --- a/client/coral-plugin-flags/FlagButton.js +++ b/client/coral-plugin-flags/FlagButton.js @@ -4,18 +4,21 @@ import translations from './translations.json'; const name = 'coral-plugin-flags'; -const FlagButton = ({flag, id, postAction, deleteAction, addItem, updateItem, addNotification}) => { +const FlagButton = ({flag, id, postAction, deleteAction, addItem, updateItem, addNotification, currentUser}) => { const flagged = flag && flag.current_user; const onFlagClick = () => { + if (!currentUser) { + return; + } if (!flagged) { - postAction(id, 'flag', '123', 'comments') + postAction(id, 'flag', currentUser.id, 'comments') .then((action) => { addItem({...action, current_user:true}, 'actions'); updateItem(action.item_id, action.action_type, action.id, 'comments'); }); addNotification('success', lang.t('flag-notif')); } else { - deleteAction(id, 'flag', '123', 'comments') + deleteAction(id, 'flag', currentUser.id, 'comments') .then(() => { updateItem(id, 'flag', '', 'comments'); }); diff --git a/client/coral-plugin-likes/LikeButton.js b/client/coral-plugin-likes/LikeButton.js index 9bdf7b84d..ecdffaf62 100644 --- a/client/coral-plugin-likes/LikeButton.js +++ b/client/coral-plugin-likes/LikeButton.js @@ -4,17 +4,20 @@ import translations from './translations.json'; const name = 'coral-plugin-flags'; -const LikeButton = ({like, id, postAction, deleteAction, addItem, updateItem}) => { +const LikeButton = ({like, id, postAction, deleteAction, addItem, updateItem, currentUser}) => { const liked = like && like.current_user; const onLikeClick = () => { + if (!currentUser) { + return; + } if (!liked) { - postAction(id, 'like', '123', 'comments') + postAction(id, 'like', currentUser.id, 'comments') .then((action) => { addItem({id: action.id, current_user:true, count: like ? like.count + 1 : 1}, 'actions'); updateItem(action.item_id, action.action_type, action.id, 'comments'); }); } else { - deleteAction(id, 'like', '123', 'comments') + deleteAction(id, 'like', currentUser.id, 'comments') .then(() => { updateItem(like.id, 'count', like.count - 1, 'actions'); updateItem(like.id, 'current_user', false, 'actions');