From 685f5483f6a60d902eea621800e746789949859d Mon Sep 17 00:00:00 2001 From: wlren Date: Mon, 10 Oct 2022 01:31:55 +0800 Subject: [PATCH] [questions][ui] add comments & commments page --- .../components/questions/CommentListItem.tsx | 38 +++++ .../questions/card/FullAnswerCard.tsx | 38 +++++ .../answer/[answerId]/[answerSlug]/index.tsx | 153 ++++++++--------- .../[questionId]/[questionSlug]/index.tsx | 161 +++++++++++++----- 4 files changed, 271 insertions(+), 119 deletions(-) create mode 100644 apps/portal/src/components/questions/CommentListItem.tsx create mode 100644 apps/portal/src/components/questions/card/FullAnswerCard.tsx diff --git a/apps/portal/src/components/questions/CommentListItem.tsx b/apps/portal/src/components/questions/CommentListItem.tsx new file mode 100644 index 00000000..1cf87d50 --- /dev/null +++ b/apps/portal/src/components/questions/CommentListItem.tsx @@ -0,0 +1,38 @@ +import { format } from 'date-fns'; + +import VotingButtons from './VotingButtons'; + +export type CommentListItemProps = { + authorImageUrl: string; + authorName: string; + content: string; + createdAt: Date; + upvoteCount: number; +}; + +export default function CommentListItem({ + authorImageUrl, + authorName, + content, + createdAt, + upvoteCount, +}: CommentListItemProps) { + return ( +
+ +
+
+ {`${authorName} +

{authorName}

+

+ Posted on: {format(createdAt, 'Pp')} +

+
+

{content}

+
+
+ ); +} diff --git a/apps/portal/src/components/questions/card/FullAnswerCard.tsx b/apps/portal/src/components/questions/card/FullAnswerCard.tsx new file mode 100644 index 00000000..74282c77 --- /dev/null +++ b/apps/portal/src/components/questions/card/FullAnswerCard.tsx @@ -0,0 +1,38 @@ +import { format } from 'date-fns'; + +import VotingButtons from '../VotingButtons'; + +export type FullAnswerCardProps = { + authorImageUrl: string; + authorName: string; + content: string; + createdAt: Date; + upvoteCount: number; +}; + +export default function FullAnswerCard({ + authorImageUrl, + authorName, + content, + createdAt, + upvoteCount, +}: FullAnswerCardProps) { + return ( +
+ +
+
+ {`${authorName} +

{authorName}

+

+ Posted on: {format(createdAt, 'Pp')} +

+
+

{content}

+
+
+ ); +} diff --git a/apps/portal/src/pages/questions/[questionId]/[questionSlug]/answer/[answerId]/[answerSlug]/index.tsx b/apps/portal/src/pages/questions/[questionId]/[questionSlug]/answer/[answerId]/[answerSlug]/index.tsx index eea8f5cc..bcbd7f93 100644 --- a/apps/portal/src/pages/questions/[questionId]/[questionSlug]/answer/[answerId]/[answerSlug]/index.tsx +++ b/apps/portal/src/pages/questions/[questionId]/[questionSlug]/answer/[answerId]/[answerSlug]/index.tsx @@ -1,39 +1,45 @@ import { useRouter } from 'next/router'; import { useForm } from 'react-hook-form'; import { ArrowSmallLeftIcon } from '@heroicons/react/24/outline'; -import { Button, Collapsible, Select, TextArea } from '@tih/ui'; +import { Button, Select, TextArea } from '@tih/ui'; -import AnswerCard from '~/components/questions/card/AnswerCard'; -import FullQuestionCard from '~/components/questions/card/FullQuestionCard'; +import FullAnswerCard from '~/components/questions/card/FullAnswerCard'; +import CommentListItem from '~/components/questions/CommentListItem'; -import { SAMPLE_QUESTION } from '~/utils/questions/constants'; +import { + SAMPLE_ANSWER, + SAMPLE_ANSWER_COMMENT, + SAMPLE_QUESTION, +} from '~/utils/questions/constants'; import { useFormRegister } from '~/utils/questions/useFormRegister'; -export type AnswerData = { - answerContent: string; +export type AnswerCommentData = { + commentContent: string; }; export default function QuestionPage() { const router = useRouter(); + const { - register: formRegister, - handleSubmit, - formState: { isDirty, isValid }, - } = useForm({ mode: 'onChange' }); - const register = useFormRegister(formRegister); - const question = SAMPLE_QUESTION; + register: comRegister, + handleSubmit: handleCommentSubmit, + formState: { isDirty: isCommentDirty, isValid: isCommentValid }, + } = useForm({ mode: 'onChange' }); + const commentRegister = useFormRegister(comRegister); + const question = SAMPLE_QUESTION; + const comment = SAMPLE_ANSWER_COMMENT; const handleBackNavigation = () => { router.back(); }; - const handleSubmitAnswer = (data: AnswerData) => { + const handleSubmitComment = (data: AnswerCommentData) => { // eslint-disable-next-line no-console console.log(data); }; return ( -
+
-
-
- +
+
+
- -
Comment placeholder
-
-
-
-