From f43832187cdc282af5edb87c07cbffe0b3054bdd Mon Sep 17 00:00:00 2001 From: Mehak Nasir Date: Fri, 30 Sep 2022 17:39:20 +0500 Subject: [PATCH] fix: read/unread status fixed --- src/discussions/posts/post/PostFooter.jsx | 5 ++++- src/discussions/posts/post/PostFooter.test.jsx | 8 ++++---- src/discussions/posts/post/PostLink.jsx | 10 +++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/discussions/posts/post/PostFooter.jsx b/src/discussions/posts/post/PostFooter.jsx index 5227d38e..d321532d 100644 --- a/src/discussions/posts/post/PostFooter.jsx +++ b/src/discussions/posts/post/PostFooter.jsx @@ -30,6 +30,7 @@ function PostFooter({ post, intl, preview, + showNewCountLabel, }) { const dispatch = useDispatch(); const userHasModerationPrivileges = useSelector(selectUserHasModerationPrivileges); @@ -74,7 +75,7 @@ function PostFooter({ {post.commentCount} )} - {preview && post?.unreadCommentCount > 0 && post.commentCount > 1 && ( + {showNewCountLabel && preview && post?.unreadCommentCount > 0 && post.commentCount > 1 && ( {intl.formatMessage(messages.newLabel, { count: post.unreadCommentCount })} @@ -130,10 +131,12 @@ PostFooter.propTypes = { intl: intlShape.isRequired, post: postShape.isRequired, preview: PropTypes.bool, + showNewCountLabel: PropTypes.bool, }; PostFooter.defaultProps = { preview: false, + showNewCountLabel: false, }; export default injectIntl(PostFooter); diff --git a/src/discussions/posts/post/PostFooter.test.jsx b/src/discussions/posts/post/PostFooter.test.jsx index 988eeeff..1934f52b 100644 --- a/src/discussions/posts/post/PostFooter.test.jsx +++ b/src/discussions/posts/post/PostFooter.test.jsx @@ -14,11 +14,11 @@ import PostFooter from './PostFooter'; let store; -function renderComponent(post, preview = false) { +function renderComponent(post, preview = false, showNewCountLabel = false) { return render( - + , ); @@ -64,8 +64,8 @@ describe('PostFooter', () => { }); }); - it("shows 'x new' badge for new comments", () => { - renderComponent(mockPost, true); + it("shows 'x new' badge for new comments in case of read post only", () => { + renderComponent(mockPost, true, true); expect(screen.getByText('2 New')).toBeTruthy(); }); diff --git a/src/discussions/posts/post/PostLink.jsx b/src/discussions/posts/post/PostLink.jsx index 34b681d1..d83f4553 100644 --- a/src/discussions/posts/post/PostLink.jsx +++ b/src/discussions/posts/post/PostLink.jsx @@ -48,7 +48,7 @@ function PostLink({ const authorLabelColor = AvatarOutlineAndLabelColors[post.authorLabel]; const postReported = post.abuseFlagged || post.abuseFlaggedCount; const canSeeReportedBadge = postReported && (userHasModerationPrivileges || userIsGroupTa); - const neverRead = !post.read && post.commentCount === post.unreadCommentCount; + const read = post.read || (!post.read && post.commentCount !== post.unreadCommentCount); return ( <> @@ -68,21 +68,21 @@ function PostLink({
- +
{post.title} @@ -129,7 +129,7 @@ function PostLink({ : intl.formatMessage(messages.postWithoutPreview)}
- +