From 21bc9bdf4d26b280c2d7f47431d4ef911100f7d6 Mon Sep 17 00:00:00 2001 From: Jeff Sieu Date: Sun, 9 Oct 2022 03:46:39 +0800 Subject: [PATCH] [question][ui] add question detail page --- .../components/questions/VotingButtons.tsx | 26 ++++++++++++++ .../components/questions/card/AnswerCard.tsx | 23 ++++++++++++ .../questions/card/QuestionCard.tsx | 36 +++++++++---------- .../questions/card/QuestionOverviewCard.tsx | 24 ++++++------- .../questions/card/SimilarQuestionCard.tsx | 28 +++++++-------- .../src/pages/questions/[id]/[slug]/index.tsx | 35 ++++++++++++++++++ apps/portal/src/pages/questions/index.tsx | 10 ++---- apps/portal/src/utils/questions/constants.ts | 11 ++++++ 8 files changed, 138 insertions(+), 55 deletions(-) create mode 100644 apps/portal/src/components/questions/VotingButtons.tsx create mode 100644 apps/portal/src/components/questions/card/AnswerCard.tsx create mode 100644 apps/portal/src/pages/questions/[id]/[slug]/index.tsx diff --git a/apps/portal/src/components/questions/VotingButtons.tsx b/apps/portal/src/components/questions/VotingButtons.tsx new file mode 100644 index 00000000..81a6d7b1 --- /dev/null +++ b/apps/portal/src/components/questions/VotingButtons.tsx @@ -0,0 +1,26 @@ +import { ChevronDownIcon, ChevronUpIcon } from '@heroicons/react/24/outline'; +import { Button } from '@tih/ui'; + +export type VotingButtonsProps = { + upvoteCount: number; +}; + +export default function VotingButtons({ upvoteCount }: VotingButtonsProps) { + return ( +
+
+ ); +} diff --git a/apps/portal/src/components/questions/card/AnswerCard.tsx b/apps/portal/src/components/questions/card/AnswerCard.tsx new file mode 100644 index 00000000..eb9fe9fd --- /dev/null +++ b/apps/portal/src/components/questions/card/AnswerCard.tsx @@ -0,0 +1,23 @@ +import VotingButtons from '../VotingButtons'; + +export type AnswerCardProps = { + author: string; + content: string; + upvoteCount: number; +}; + +export default function AnswerCard({ + author, + upvoteCount, + content, +}: AnswerCardProps) { + return ( +
+ +
+

{author}

+

{content}

+
+
+ ); +} diff --git a/apps/portal/src/components/questions/card/QuestionCard.tsx b/apps/portal/src/components/questions/card/QuestionCard.tsx index b94366e5..08c1b7be 100644 --- a/apps/portal/src/components/questions/card/QuestionCard.tsx +++ b/apps/portal/src/components/questions/card/QuestionCard.tsx @@ -1,11 +1,11 @@ import { ChatBubbleBottomCenterTextIcon, - ChevronDownIcon, - ChevronUpIcon, EyeIcon, } from '@heroicons/react/24/outline'; import { Badge, Button } from '@tih/ui'; +import VotingButtons from '../VotingButtons'; + type UpvoteProps = | { showVoteButtons: true; @@ -42,6 +42,7 @@ export type QuestionCardProps = ActionButtonProps & StatisticsProps & UpvoteProps & { content: string; + href?: string; location: string; receivedCount: number; role: string; @@ -61,26 +62,11 @@ export default function QuestionCard({ timestamp, role, location, + href, }: QuestionCardProps) { - return ( + const mainCard = (
- {showVoteButtons && ( -
-
- )} + {showVoteButtons && }
@@ -122,4 +108,14 @@ export default function QuestionCard({
); + + return href ? ( + + {mainCard} + + ) : ( + mainCard + ); } diff --git a/apps/portal/src/components/questions/card/QuestionOverviewCard.tsx b/apps/portal/src/components/questions/card/QuestionOverviewCard.tsx index 0c61ece3..ecb4eb2e 100644 --- a/apps/portal/src/components/questions/card/QuestionOverviewCard.tsx +++ b/apps/portal/src/components/questions/card/QuestionOverviewCard.tsx @@ -1,19 +1,17 @@ import type { QuestionCardProps } from './QuestionCard'; import QuestionCard from './QuestionCard'; -export type QuestionOverviewCardProps = Required< - Omit< - QuestionCardProps & { - showActionButton: false; - showUserStatistics: true; - showVoteButtons: true; - }, - | 'actionButtonLabel' - | 'onActionButtonClick' - | 'showActionButton' - | 'showUserStatistics' - | 'showVoteButtons' - > +export type QuestionOverviewCardProps = Omit< + QuestionCardProps & { + showActionButton: false; + showUserStatistics: true; + showVoteButtons: true; + }, + | 'actionButtonLabel' + | 'onActionButtonClick' + | 'showActionButton' + | 'showUserStatistics' + | 'showVoteButtons' >; export default function QuestionOverviewCard(props: QuestionOverviewCardProps) { diff --git a/apps/portal/src/components/questions/card/SimilarQuestionCard.tsx b/apps/portal/src/components/questions/card/SimilarQuestionCard.tsx index 0b591fb8..063bdf91 100644 --- a/apps/portal/src/components/questions/card/SimilarQuestionCard.tsx +++ b/apps/portal/src/components/questions/card/SimilarQuestionCard.tsx @@ -1,21 +1,19 @@ import type { QuestionCardProps } from './QuestionCard'; import QuestionCard from './QuestionCard'; -export type SimilarQuestionCardProps = Required< - Omit< - QuestionCardProps & { - showActionButton: true; - showUserStatistics: false; - showVoteButtons: false; - }, - | 'actionButtonLabel' - | 'answerCount' - | 'onActionButtonClick' - | 'showActionButton' - | 'showUserStatistics' - | 'showVoteButtons' - | 'upvoteCount' - > +export type SimilarQuestionCardProps = Omit< + QuestionCardProps & { + showActionButton: true; + showUserStatistics: false; + showVoteButtons: false; + }, + | 'actionButtonLabel' + | 'answerCount' + | 'onActionButtonClick' + | 'showActionButton' + | 'showUserStatistics' + | 'showVoteButtons' + | 'upvoteCount' > & { onSimilarQuestionClick: () => void; }; diff --git a/apps/portal/src/pages/questions/[id]/[slug]/index.tsx b/apps/portal/src/pages/questions/[id]/[slug]/index.tsx new file mode 100644 index 00000000..f5f8b0d0 --- /dev/null +++ b/apps/portal/src/pages/questions/[id]/[slug]/index.tsx @@ -0,0 +1,35 @@ +import { Button, Collapsible, TextArea } from '@tih/ui'; + +import AnswerCard from '~/components/questions/card/AnswerCard'; +import QuestionOverviewCard from '~/components/questions/card/QuestionOverviewCard'; + +import { SAMPLE_QUESTION } from '~/utils/questions/constants'; + +export default function QuestionPage() { + const question = SAMPLE_QUESTION; + return ( +
+
+

Question overview

+ + +
Comment placeholder
+
+