From 2661e850893118537827bee111b6daf41fedf8ad Mon Sep 17 00:00:00 2001 From: Ben Furber Date: Thu, 30 May 2024 14:08:25 +0100 Subject: [PATCH] feat: update counts to exclude deleted comments --- .../ButtonShowReplies/ButtonShowReplies.tsx | 7 +++--- .../src/CommentItem/CommentItem.tsx | 2 +- .../DiscussionContainer.tsx | 2 +- .../DiscussionTitle.stories.tsx | 18 ++++++++------ .../DiscussionTitle/DiscussionTitle.test.tsx | 2 +- .../src/DiscussionTitle/DiscussionTitle.tsx | 18 ++++++++++---- src/common/DiscussionWrapper.tsx | 4 +++- src/models/question.models.tsx | 1 + src/pages/Question/QuestionPage.tsx | 1 + src/stores/Discussions/discussionEvents.ts | 9 +++++-- src/utils/filterNonDeletedComments.test.ts | 19 +++++++++++++++ src/utils/filterNonDeletedComments.ts | 5 ++++ src/utils/nonDeletedCommentsCount.test.ts | 24 +++++++++++++++++++ src/utils/nonDeletedCommentsCount.ts | 7 ++++++ 14 files changed, 97 insertions(+), 22 deletions(-) create mode 100644 src/utils/filterNonDeletedComments.test.ts create mode 100644 src/utils/filterNonDeletedComments.ts create mode 100644 src/utils/nonDeletedCommentsCount.test.ts create mode 100644 src/utils/nonDeletedCommentsCount.ts diff --git a/packages/components/src/ButtonShowReplies/ButtonShowReplies.tsx b/packages/components/src/ButtonShowReplies/ButtonShowReplies.tsx index b6708cc1c2..ca8b0f14ea 100644 --- a/packages/components/src/ButtonShowReplies/ButtonShowReplies.tsx +++ b/packages/components/src/ButtonShowReplies/ButtonShowReplies.tsx @@ -1,4 +1,5 @@ import { Button } from '../Button/Button' +import { nonDeletedCommentsCount } from '../DiscussionTitle/DiscussionTitle' import type { IComment } from '../CommentItem/types' @@ -12,12 +13,10 @@ export interface Props { export const ButtonShowReplies = (props: Props) => { const { creatorName, isShowReplies, replies, setIsShowReplies } = props - const length = replies && replies.length ? replies.length : 0 + const count = nonDeletedCommentsCount(replies) const icon = isShowReplies ? 'arrow-full-up' : 'arrow-full-down' - const text = length - ? `${length} ${length === 1 ? 'reply' : 'replies'}` - : `Reply` + const text = count ? `${count} ${count === 1 ? 'reply' : 'replies'}` : `Reply` return (