From fd67a20a2b02519576d3d11fe5db88c35dcd9996 Mon Sep 17 00:00:00 2001 From: Terence <45381509+Vielheim@users.noreply.github.com> Date: Thu, 13 Oct 2022 11:57:45 +0800 Subject: [PATCH] [resumes][fix] Fix bugs in comments section (#363) * [resumes][fix] left-align all comments * [resumes][fix] add comment owner OP tag * [resumes][fix] render multi-line text in comments * [resumes][feat] add see more/less for overflow comments * [resumes][refactor] prefix comments section with Resume * [resumes][refactor] Refactor routers from reviews -> comments * [resumes][refactor] use Vote enum in ResumesCommentVote * [resumes][refactor] add comment count to tabs * [resumes][refactor] combine resume-card and resume-body into resume-list-item Co-authored-by: Terence Ho <> --- .../migration.sql | 9 ++ apps/portal/prisma/schema.prisma | 2 +- .../resumes/comments/CommentListItems.tsx | 35 -------- .../resumes/comments/CommentsList.tsx | 54 ------------ .../comments/ResumeCommentListItem.tsx | 77 +++++++++++++++++ ...ommentsForm.tsx => ResumeCommentsForm.tsx} | 37 ++++---- .../resumes/comments/ResumeCommentsList.tsx | 86 +++++++++++++++++++ ...sSection.tsx => ResumeCommentsSection.tsx} | 16 ++-- .../resumes/comments/comment/Comment.tsx | 18 ---- .../resumes/comments/comment/CommentBody.tsx | 64 -------------- .../resumes/comments/comment/CommentCard.tsx | 22 ----- ...constants.ts => resumeCommentConstants.ts} | 2 +- .../resumes/shared/ResumeExpandableText.tsx | 48 +++++++++++ apps/portal/src/pages/resumes/[resumeId].tsx | 6 +- apps/portal/src/server/router/index.ts | 8 +- ...s-router.ts => resumes-comments-router.ts} | 2 +- ...ter.ts => resumes-comments-user-router.ts} | 6 +- apps/portal/src/types/resume-comments.d.ts | 6 +- 18 files changed, 265 insertions(+), 233 deletions(-) create mode 100644 apps/portal/prisma/migrations/20221013032033_update_resume_vote_to_enum/migration.sql delete mode 100644 apps/portal/src/components/resumes/comments/CommentListItems.tsx delete mode 100644 apps/portal/src/components/resumes/comments/CommentsList.tsx create mode 100644 apps/portal/src/components/resumes/comments/ResumeCommentListItem.tsx rename apps/portal/src/components/resumes/comments/{CommentsForm.tsx => ResumeCommentsForm.tsx} (82%) create mode 100644 apps/portal/src/components/resumes/comments/ResumeCommentsList.tsx rename apps/portal/src/components/resumes/comments/{CommentsSection.tsx => ResumeCommentsSection.tsx} (72%) delete mode 100644 apps/portal/src/components/resumes/comments/comment/Comment.tsx delete mode 100644 apps/portal/src/components/resumes/comments/comment/CommentBody.tsx delete mode 100644 apps/portal/src/components/resumes/comments/comment/CommentCard.tsx rename apps/portal/src/components/resumes/comments/{constants.ts => resumeCommentConstants.ts} (90%) create mode 100644 apps/portal/src/components/resumes/shared/ResumeExpandableText.tsx rename apps/portal/src/server/router/resumes/{resumes-reviews-router.ts => resumes-comments-router.ts} (95%) rename apps/portal/src/server/router/resumes/{resumes-reviews-user-router.ts => resumes-comments-user-router.ts} (89%) diff --git a/apps/portal/prisma/migrations/20221013032033_update_resume_vote_to_enum/migration.sql b/apps/portal/prisma/migrations/20221013032033_update_resume_vote_to_enum/migration.sql new file mode 100644 index 00000000..935df922 --- /dev/null +++ b/apps/portal/prisma/migrations/20221013032033_update_resume_vote_to_enum/migration.sql @@ -0,0 +1,9 @@ +/* + Warnings: + + - Changed the type of `value` on the `ResumesCommentVote` table. No cast exists, the column would be dropped and recreated, which cannot be done if there is data, since the column is required. + +*/ +-- AlterTable +ALTER TABLE "ResumesCommentVote" DROP COLUMN "value", +ADD COLUMN "value" "Vote" NOT NULL; diff --git a/apps/portal/prisma/schema.prisma b/apps/portal/prisma/schema.prisma index 27a1d7c5..9ce74736 100644 --- a/apps/portal/prisma/schema.prisma +++ b/apps/portal/prisma/schema.prisma @@ -159,7 +159,7 @@ model ResumesCommentVote { id String @id @default(cuid()) userId String commentId String - value Int + value Vote createdAt DateTime @default(now()) updatedAt DateTime @updatedAt comment ResumesComment @relation(fields: [commentId], references: [id], onDelete: Cascade) diff --git a/apps/portal/src/components/resumes/comments/CommentListItems.tsx b/apps/portal/src/components/resumes/comments/CommentListItems.tsx deleted file mode 100644 index 5e3e154d..00000000 --- a/apps/portal/src/components/resumes/comments/CommentListItems.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import { useSession } from 'next-auth/react'; -import { Spinner } from '@tih/ui'; - -import Comment from './comment/Comment'; - -import type { ResumeComment } from '~/types/resume-comments'; - -type Props = Readonly<{ - comments: Array; - isLoading: boolean; -}>; - -export default function CommentListItems({ comments, isLoading }: Props) { - const { data: session } = useSession(); - - if (isLoading) { - return ( -
- -
- ); - } - - return ( -
- {comments.map((comment) => ( - - ))} -
- ); -} diff --git a/apps/portal/src/components/resumes/comments/CommentsList.tsx b/apps/portal/src/components/resumes/comments/CommentsList.tsx deleted file mode 100644 index e4f842cb..00000000 --- a/apps/portal/src/components/resumes/comments/CommentsList.tsx +++ /dev/null @@ -1,54 +0,0 @@ -import { useSession } from 'next-auth/react'; -import { useState } from 'react'; -import { Tabs } from '@tih/ui'; -import { Button } from '@tih/ui'; - -import { trpc } from '~/utils/trpc'; - -import CommentListItems from './CommentListItems'; -import { COMMENTS_SECTIONS } from './constants'; -import ResumeSignInButton from '../shared/ResumeSignInButton'; - -type CommentsListProps = Readonly<{ - resumeId: string; - setShowCommentsForm: (show: boolean) => void; -}>; - -export default function CommentsList({ - resumeId, - setShowCommentsForm, -}: CommentsListProps) { - const { data: sessionData } = useSession(); - const [tab, setTab] = useState(COMMENTS_SECTIONS[0].value); - - const commentsQuery = trpc.useQuery(['resumes.reviews.list', { resumeId }]); - const renderButton = () => { - if (sessionData === null) { - return ; - } - return ( -