From 21d0339d3d4a99cf72c1835bb811b7e98afa84a4 Mon Sep 17 00:00:00 2001 From: Paul Mineev Date: Thu, 21 Apr 2022 18:49:03 -0700 Subject: [PATCH] restore low_score comment state --- .../app/components/comment/comment-votes.spec.tsx | 12 ------------ frontend/app/components/comment/comment-votes.tsx | 5 ++--- frontend/app/components/comment/comment.tsx | 8 ++++++++ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/frontend/app/components/comment/comment-votes.spec.tsx b/frontend/app/components/comment/comment-votes.spec.tsx index 807a7a3e..241b9092 100644 --- a/frontend/app/components/comment/comment-votes.spec.tsx +++ b/frontend/app/components/comment/comment-votes.spec.tsx @@ -104,16 +104,4 @@ describe('', () => { expect(screen.getByTitle('Vote up')).toBeVisible(); expect(screen.getByTitle('Vote up')).not.toBeDisabled(); }); - - it('should disable downvote ability when `low_score` is reached', async () => { - StaticStore.config.low_score = -4; - jest.spyOn(api, 'putCommentVote').mockImplementation(jest.fn(async () => ({ id: '1', score: -4 }))); - render(); - expect(screen.getByTitle('Vote down')).not.toBeDisabled(); - fireEvent(screen.getByTitle('Vote down'), new Event('click')); - await waitFor(() => { - expect(screen.getByTitle('Vote down')).toBeDisabled(); - expect(screen.getByTitle('Vote up')).toBeDisabled(); - }); - }); }); diff --git a/frontend/app/components/comment/comment-votes.tsx b/frontend/app/components/comment/comment-votes.tsx index 890207d9..8cc39bad 100644 --- a/frontend/app/components/comment/comment-votes.tsx +++ b/frontend/app/components/comment/comment-votes.tsx @@ -44,11 +44,10 @@ export function CommentVotes({ id, votes, vote, disabled, controversy = 0 }: Pro } } - const lowScore = StaticStore.config.low_score === votes; - const positiveScore = StaticStore.config.positive_score; const isUpvoted = vote === 1; const isDownvoted = vote === -1; const value = loadingState?.votes ?? votes; + const isPositiveScore = StaticStore.config.positive_score && value > -1; return ( @@ -58,7 +57,7 @@ export function CommentVotes({ id, votes, vote, disabled, controversy = 0 }: Pro onClick={handleClick} data-value={-1} title={intl.formatMessage(messages.downvote)} - disabled={lowScore || loadingState !== null || isDownvoted || (positiveScore && value > -1)} + disabled={loadingState !== null || isDownvoted || isPositiveScore} > diff --git a/frontend/app/components/comment/comment.tsx b/frontend/app/components/comment/comment.tsx index 8e59f224..b8439e00 100644 --- a/frontend/app/components/comment/comment.tsx +++ b/frontend/app/components/comment/comment.tsx @@ -326,6 +326,14 @@ export class Comment extends Component { const defaultMods = { disabled: props.disabled, pinned: props.data.pin, + // TODO: we also have critical_score, so we need to collapse comments with it in future + useless: + !!props.isUserBanned || + !!props.data.delete || + (props.view !== 'preview' && + props.data.score < StaticStore.config.low_score && + !props.data.pin && + !props.disabled), // TODO: add default view mod or don't? guest: isGuest, view: props.view === 'main' || props.view === 'pinned' ? props.data.user.admin && 'admin' : props.view,