[resumes][refactor] update comments ui

pull/418/head
Terence Ho 3 years ago
parent 5844c52efe
commit 7029f17be1

@ -1,4 +1,5 @@
import clsx from 'clsx'; import clsx from 'clsx';
import { formatDistanceToNow } from 'date-fns';
import { useState } from 'react'; import { useState } from 'react';
import { ChevronUpIcon } from '@heroicons/react/20/solid'; import { ChevronUpIcon } from '@heroicons/react/20/solid';
import { FaceSmileIcon } from '@heroicons/react/24/outline'; import { FaceSmileIcon } from '@heroicons/react/24/outline';
@ -26,12 +27,7 @@ export default function ResumeCommentListItem({
const [showReplies, setShowReplies] = useState(true); const [showReplies, setShowReplies] = useState(true);
return ( return (
<div <div className="min-w-fit">
className={clsx(
'min-w-fit rounded-md bg-white ',
!comment.parentId &&
'border-primary-300 w-11/12 border-2 p-2 drop-shadow-md',
)}>
<div className="flex flex-row space-x-2 p-1 align-top"> <div className="flex flex-row space-x-2 p-1 align-top">
{/* Image Icon */} {/* Image Icon */}
{comment.user.image ? ( {comment.user.image ? (
@ -58,7 +54,7 @@ export default function ResumeCommentListItem({
<div className="flex flex-row items-center space-x-1"> <div className="flex flex-row items-center space-x-1">
<p <p
className={clsx( className={clsx(
'font-medium text-black', 'font-medium text-gray-800',
!!comment.parentId && 'text-sm', !!comment.parentId && 'text-sm',
)}> )}>
{comment.user.name ?? 'Reviewer ABC'} {comment.user.name ?? 'Reviewer ABC'}
@ -72,9 +68,8 @@ export default function ResumeCommentListItem({
</div> </div>
<div className="px-2 text-xs text-slate-600"> <div className="px-2 text-xs text-slate-600">
{comment.createdAt.toLocaleString('en-US', { {formatDistanceToNow(comment.createdAt, {
dateStyle: 'medium', addSuffix: true,
timeStyle: 'short',
})} })}
</div> </div>
</div> </div>
@ -86,10 +81,12 @@ export default function ResumeCommentListItem({
setIsEditingComment={setIsEditingComment} setIsEditingComment={setIsEditingComment}
/> />
) : ( ) : (
<ResumeExpandableText <div className="text-gray-800">
key={comment.description} <ResumeExpandableText
text={comment.description} key={comment.description}
/> text={comment.description}
/>
</div>
)} )}
{/* Upvote and edit */} {/* Upvote and edit */}
@ -143,7 +140,15 @@ export default function ResumeCommentListItem({
!showReplies && 'rotate-180 transform', !showReplies && 'rotate-180 transform',
)} )}
/> />
<span>{showReplies ? 'Hide replies' : 'Show replies'}</span> <span>
{showReplies
? `Hide ${
comment.children.length === 1 ? 'reply' : 'replies'
}`
: `Show ${comment.children.length} ${
comment.children.length === 1 ? 'reply' : 'replies'
}`}
</span>
</button> </button>
{showReplies && ( {showReplies && (
@ -152,7 +157,7 @@ export default function ResumeCommentListItem({
<div className="flex-grow border-r border-slate-300" /> <div className="flex-grow border-r border-slate-300" />
</div> </div>
<div className="flex flex-col space-y-1"> <div className="flex flex-1 flex-col space-y-1">
{comment.children.map((child) => { {comment.children.map((child) => {
return ( return (
<ResumeCommentListItem <ResumeCommentListItem

@ -2,6 +2,7 @@ import { useSession } from 'next-auth/react';
import { import {
BookOpenIcon, BookOpenIcon,
BriefcaseIcon, BriefcaseIcon,
ChatBubbleLeftRightIcon,
CodeBracketSquareIcon, CodeBracketSquareIcon,
FaceSmileIcon, FaceSmileIcon,
IdentificationIcon, IdentificationIcon,
@ -91,19 +92,33 @@ export default function ResumeCommentsList({
<div className="w-fit text-lg font-medium">{label}</div> <div className="w-fit text-lg font-medium">{label}</div>
</div> </div>
{commentCount > 0 ? ( <div className="w-11/12 space-y-4">
comments.map((comment) => { <div className=" space-y-2 rounded-md border-2 border-indigo-300 bg-white px-4 py-3 drop-shadow-md">
return ( {commentCount > 0 ? (
<ResumeCommentListItem comments.map((comment) => {
key={comment.id} return (
comment={comment} <ResumeCommentListItem
userId={sessionData?.user?.id} key={comment.id}
/> comment={comment}
); userId={sessionData?.user?.id}
}) />
) : ( );
<div>There are no comments for this section yet!</div> })
)} ) : (
<div className="flex flex-row items-center text-sm">
<ChatBubbleLeftRightIcon className="mr-2 h-6 w-6 text-indigo-400" />
<div className="text-gray-500">
There are no comments for this section yet!
</div>
</div>
)}
</div>
</div>
<div className="relative flex flex-row pr-6 pt-2">
<div className="flex-grow border-t border-gray-300" />
</div>
</div> </div>
); );
})} })}

@ -97,7 +97,7 @@ export default function ResumeCommentVoteButtons({
/> />
</button> </button>
<div className="flex min-w-[1rem] justify-center text-xs"> <div className="flex min-w-[1rem] justify-center text-xs font-semibold text-gray-700">
{commentVotesQuery.data?.numVotes ?? 0} {commentVotesQuery.data?.numVotes ?? 0}
</div> </div>

Loading…
Cancel
Save