From da761468b66720478c3bd7f9b8385dd9d590ad22 Mon Sep 17 00:00:00 2001 From: David Jay Date: Mon, 23 Jan 2017 16:18:51 -0500 Subject: [PATCH] Enabling like buttons. --- client/coral-embed-stream/src/Embed.js | 2 +- client/coral-plugin-likes/LikeButton.js | 101 ++++++++++++++++-------- 2 files changed, 67 insertions(+), 36 deletions(-) diff --git a/client/coral-embed-stream/src/Embed.js b/client/coral-embed-stream/src/Embed.js index 4d44a10b6..cd55c13cd 100644 --- a/client/coral-embed-stream/src/Embed.js +++ b/client/coral-embed-stream/src/Embed.js @@ -151,7 +151,7 @@ class Embed extends Component { currentUser={user} postAction={this.props.postAction} deleteAction={this.props.deleteAction} - showSignInDialog={showSignInDialog} + showSignInDialog={this.props.showSignInDialog} comments={asset.comments} /> { - const liked = like && like.current; - const onLikeClick = () => { - if (!currentUser) { - const offset = document.getElementById(`c_${id}`).getBoundingClientRect().top - 75; - showSignInDialog(offset); - return; - } - if (currentUser.banned) { - return; - } - if (!liked) { - postAction({ - item_id: id, - item_type: 'COMMENTS', - action_type: 'LIKE' - }); - // TODO: frontend update from mutation - } else { - deleteAction(liked.id); - } - }; +class LikeButton extends Component { - return
- -
; -}; + if (currentUser.banned) { + return; + } + if (!liked) { + this.setState({localPost: 'temp', localDelete: false}); + postAction({ + item_id: id, + item_type: 'COMMENTS', + action_type: 'LIKE' + }).then(({data}) => { + this.setState({localPost: data.createAction.id}); + }); + } else { + this.setState((prev) => prev.localPost ? {...prev, localPost: null} : {...prev, localDelete: true}); + deleteAction(localPost || like.current.id); + } + }; + + return
+ +
; + } +} export default LikeButton;