From 63ce107cc1a19bd8209771038dac89c84313e7e2 Mon Sep 17 00:00:00 2001 From: jessop Date: Tue, 29 Sep 2020 10:10:23 -0400 Subject: [PATCH] comment reactions --- flow-typed/Comment.js | 12 ++++ package.json | 2 +- static/app-strings.json | 20 +++++- ui/component/comment/view.jsx | 2 +- ui/component/commentReactions/index.js | 11 ++- ui/component/commentReactions/view.jsx | 29 ++++++-- ui/component/commentsList/index.js | 3 +- ui/component/commentsList/view.jsx | 20 +++++- ui/constants/action_types.js | 6 ++ ui/redux/actions/comments.js | 99 +++++++++++++++++++++++++- ui/redux/reducers/comments.js | 42 ++++++++++- ui/redux/selectors/comments.js | 16 +++++ ui/scss/component/_comments.scss | 2 +- yarn.lock | 4 +- 14 files changed, 252 insertions(+), 16 deletions(-) diff --git a/flow-typed/Comment.js b/flow-typed/Comment.js index c9d32b835..bef306e31 100644 --- a/flow-typed/Comment.js +++ b/flow-typed/Comment.js @@ -22,4 +22,16 @@ declare type CommentsState = { commentById: { [string]: Comment }, isLoading: boolean, myComments: ?Set, + isFetchingReacts: boolean, + myReactsByCommentId: any, + othersReactsByCommentId: any, }; + +declare type CommentReactParams = { + comment_ids: string, + channel_name: string, + channel_id: string, + react_type: string, + clear_types?: string, + remove?: boolean, +} diff --git a/package.json b/package.json index 5370b3f73..c74f2da04 100644 --- a/package.json +++ b/package.json @@ -136,7 +136,7 @@ "imagesloaded": "^4.1.4", "json-loader": "^0.5.4", "lbry-format": "https://github.com/lbryio/lbry-format.git", - "lbry-redux": "lbryio/lbry-redux#90012bf47c170f244039261548dab7c7597046dc", + "lbry-redux": "lbryio/lbry-redux#04015155796bc588bdf5b10762cfc874e6a1b00c", "lbryinc": "lbryio/lbryinc#db0663fcc4a64cb082b6edc5798fafa67eb4300f", "lint-staged": "^7.0.2", "localforage": "^1.7.1", diff --git a/static/app-strings.json b/static/app-strings.json index 441bcb65c..7deb6252d 100644 --- a/static/app-strings.json +++ b/static/app-strings.json @@ -1175,7 +1175,6 @@ "Uncheck your email below if you want to stop receiving messages.": "Uncheck your email below if you want to stop receiving messages.", "Remove from blocked list": "Remove from blocked list", "Are you sure you want to remove this from the list?": "Are you sure you want to remove this from the list?", - "Send a tip": "Send a tip", "Send a chunk of change to this creator to let them know you appreciate their content.": "Send a chunk of change to this creator to let them know you appreciate their content.", "CableTube Escape Artists": "CableTube Escape Artists", "Unlink YouTube Channel": "Unlink YouTube Channel", @@ -1279,5 +1278,24 @@ "Something went wrong. Please %click_here% to learn about sync limitations.": "Something went wrong. Please %click_here% to learn about sync limitations.", "Buy LBC": "Buy LBC", "Continue...": "Continue...", + "Leave a comment": "Leave a comment", + "Be the first to comment!": "Be the first to comment!", + "Comment as": "Comment as", + "No uploads": "No uploads", + "You haven't uploaded anything yet. This is where you can find them when you do!": "You haven't uploaded anything yet. This is where you can find them when you do!", + "Discussion": "Discussion", + "Staked LBRY Credits": "Staked LBRY Credits", + "uploads": "uploads", + "1 comment": "1 comment", + "Upvote": "Upvote", + "Downvote": "Downvote", + "Replying as": "Replying as", + "Hide %number% Replies": "Hide %number% Replies", + "Show %number% Replies": "Show %number% Replies", + "Change to list layout": "Change to list layout", + "Create a channel": "Create a channel", + "Credit Details": "Credit Details", + "Sign In": "Sign In", + "Change to tile layout": "Change to tile layout", "--end--": "--end--" } diff --git a/ui/component/comment/view.jsx b/ui/component/comment/view.jsx index 4b5e395ab..549750777 100644 --- a/ui/component/comment/view.jsx +++ b/ui/component/comment/view.jsx @@ -246,7 +246,6 @@ function Comment(props: Props) {
- {!hideReplyButton && (
)} diff --git a/ui/component/commentReactions/index.js b/ui/component/commentReactions/index.js index baddf0e25..9dc76dafe 100644 --- a/ui/component/commentReactions/index.js +++ b/ui/component/commentReactions/index.js @@ -1,8 +1,15 @@ import { connect } from 'react-redux'; import Comment from './view'; +import { makeSelectMyReactionsForComment, makeSelectOthersReactionsForComment } from 'redux/selectors/comments'; +import { doCommentReact } from 'redux/actions/comments'; -const select = (state, props) => ({}); +const select = (state, props) => ({ + myReacts: makeSelectMyReactionsForComment(props.commentId)(state), + othersReacts: makeSelectOthersReactionsForComment(props.commentId)(state), +}); -const perform = dispatch => ({}); +const perform = dispatch => ({ + react: (commentId, type) => dispatch(doCommentReact(commentId, type)), +}); export default connect(select, perform)(Comment); diff --git a/ui/component/commentReactions/view.jsx b/ui/component/commentReactions/view.jsx index 716832b0a..d23d70981 100644 --- a/ui/component/commentReactions/view.jsx +++ b/ui/component/commentReactions/view.jsx @@ -4,13 +4,29 @@ import * as REACTION_TYPES from 'constants/reactions'; import React from 'react'; import classnames from 'classnames'; import Button from 'component/button'; +import usePersistedState from 'effects/use-persisted-state'; type Props = { - myReaction: ?string, + myReacts: Array, + othersReacts: any, + react: (string, string) => void, + commentId: string, }; export default function CommentReactions(props: Props) { - const { myReaction } = props; + const { myReacts, othersReacts, commentId, react } = props; + const [activeChannel] = usePersistedState('comment-channel'); + + const getCountForReact = type => { + let count = 0; + if (othersReacts && othersReacts[type]) { + count += othersReacts[type]; + } + if (myReacts && myReacts.includes(type)) { + count += 1; + } + return count; + }; return ( <> @@ -18,15 +34,20 @@ export default function CommentReactions(props: Props) { title={__('Upvote')} icon={ICONS.UPVOTE} className={classnames('comment__action', { - 'comment__action--active': myReaction === REACTION_TYPES.LIKE, + 'comment__action--active': myReacts && myReacts.includes(REACTION_TYPES.LIKE), })} + disabled={!activeChannel} + onClick={() => react(commentId, REACTION_TYPES.LIKE)} + label={getCountForReact(REACTION_TYPES.LIKE)} />