From 7029f17be14a54281be20453537c8cf4d7b6c255 Mon Sep 17 00:00:00 2001 From: Terence Ho <> Date: Sun, 23 Oct 2022 21:53:21 +0800 Subject: [PATCH] [resumes][refactor] update comments ui --- .../comments/ResumeCommentListItem.tsx | 37 +++++++++-------- .../resumes/comments/ResumeCommentsList.tsx | 41 +++++++++++++------ .../comment/ResumeCommentVoteButtons.tsx | 2 +- 3 files changed, 50 insertions(+), 30 deletions(-) diff --git a/apps/portal/src/components/resumes/comments/ResumeCommentListItem.tsx b/apps/portal/src/components/resumes/comments/ResumeCommentListItem.tsx index dd44d4b4..98384595 100644 --- a/apps/portal/src/components/resumes/comments/ResumeCommentListItem.tsx +++ b/apps/portal/src/components/resumes/comments/ResumeCommentListItem.tsx @@ -1,4 +1,5 @@ import clsx from 'clsx'; +import { formatDistanceToNow } from 'date-fns'; import { useState } from 'react'; import { ChevronUpIcon } from '@heroicons/react/20/solid'; import { FaceSmileIcon } from '@heroicons/react/24/outline'; @@ -26,12 +27,7 @@ export default function ResumeCommentListItem({ const [showReplies, setShowReplies] = useState(true); return ( -
+
{/* Image Icon */} {comment.user.image ? ( @@ -58,7 +54,7 @@ export default function ResumeCommentListItem({

{comment.user.name ?? 'Reviewer ABC'} @@ -72,9 +68,8 @@ export default function ResumeCommentListItem({

- {comment.createdAt.toLocaleString('en-US', { - dateStyle: 'medium', - timeStyle: 'short', + {formatDistanceToNow(comment.createdAt, { + addSuffix: true, })}
@@ -86,10 +81,12 @@ export default function ResumeCommentListItem({ setIsEditingComment={setIsEditingComment} /> ) : ( - +
+ +
)} {/* Upvote and edit */} @@ -143,7 +140,15 @@ export default function ResumeCommentListItem({ !showReplies && 'rotate-180 transform', )} /> - {showReplies ? 'Hide replies' : 'Show replies'} + + {showReplies + ? `Hide ${ + comment.children.length === 1 ? 'reply' : 'replies' + }` + : `Show ${comment.children.length} ${ + comment.children.length === 1 ? 'reply' : 'replies' + }`} + {showReplies && ( @@ -152,7 +157,7 @@ export default function ResumeCommentListItem({
-
+
{comment.children.map((child) => { return ( {label}
- {commentCount > 0 ? ( - comments.map((comment) => { - return ( - - ); - }) - ) : ( -
There are no comments for this section yet!
- )} +
+
+ {commentCount > 0 ? ( + comments.map((comment) => { + return ( + + ); + }) + ) : ( +
+ + +
+ There are no comments for this section yet! +
+
+ )} +
+
+ +
+
+
); })} diff --git a/apps/portal/src/components/resumes/comments/comment/ResumeCommentVoteButtons.tsx b/apps/portal/src/components/resumes/comments/comment/ResumeCommentVoteButtons.tsx index d29ebd18..4faf1397 100644 --- a/apps/portal/src/components/resumes/comments/comment/ResumeCommentVoteButtons.tsx +++ b/apps/portal/src/components/resumes/comments/comment/ResumeCommentVoteButtons.tsx @@ -97,7 +97,7 @@ export default function ResumeCommentVoteButtons({ /> -
+
{commentVotesQuery.data?.numVotes ?? 0}