From 24944444207cade1bbc7c2d71484db1a7e764a2e Mon Sep 17 00:00:00 2001 From: wlren Date: Sun, 9 Oct 2022 21:57:42 +0800 Subject: [PATCH] [questions][ui] answer card --- .../components/questions/card/AnswerCard.tsx | 36 +++++++--- .../questions/card/FullQuestionCard.tsx | 68 +++++++++++++++++++ .../questions/card/QuestionCard.tsx | 21 ++---- .../questions/card/QuestionOverviewCard.tsx | 7 +- 4 files changed, 107 insertions(+), 25 deletions(-) create mode 100644 apps/portal/src/components/questions/card/FullQuestionCard.tsx diff --git a/apps/portal/src/components/questions/card/AnswerCard.tsx b/apps/portal/src/components/questions/card/AnswerCard.tsx index eb9fe9fd..1745522e 100644 --- a/apps/portal/src/components/questions/card/AnswerCard.tsx +++ b/apps/portal/src/components/questions/card/AnswerCard.tsx @@ -1,23 +1,43 @@ +import { format } from 'date-fns'; + +import withHref from '~/utils/questions/withHref'; + import VotingButtons from '../VotingButtons'; export type AnswerCardProps = { - author: string; + authorImageUrl: string; + authorName: string; content: string; + createdAt: Date; upvoteCount: number; }; -export default function AnswerCard({ - author, +function AnswerCardWithoutHref({ + authorName, + authorImageUrl, upvoteCount, content, + createdAt, }: AnswerCardProps) { return ( -
- -
-

{author}

-

{content}

+
+ +
+
+ {`${authorName} +

{authorName}

+

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

+
+

{content}

); } + +const AnswerCard = withHref(AnswerCardWithoutHref); +export default AnswerCard; diff --git a/apps/portal/src/components/questions/card/FullQuestionCard.tsx b/apps/portal/src/components/questions/card/FullQuestionCard.tsx new file mode 100644 index 00000000..936c6416 --- /dev/null +++ b/apps/portal/src/components/questions/card/FullQuestionCard.tsx @@ -0,0 +1,68 @@ +import { Badge } from '@tih/ui'; + +import VotingButtons from '../VotingButtons'; + +type UpvoteProps = + | { + showVoteButtons: true; + upvoteCount: number; + } + | { + showVoteButtons?: false; + upvoteCount?: never; + }; + +export type FullQuestionCardProps = UpvoteProps & { + company: string; + content: string; + href?: string; + location: string; + receivedCount: number; + role: string; + timestamp: string; +}; + +export default function FullQuestionCard({ + company, + content, + showVoteButtons, + upvoteCount, + timestamp, + role, + location, + href, +}: FullQuestionCardProps) { + const altText = company + ' logo'; + const mainCard = ( +
+ {showVoteButtons && } +
+
+ {altText} +

{company}

+
+
+
+ +

+ {timestamp} · {location} · {role} +

+
+
+
+

{content}

+
+
+
+ ); + + return href ? ( + + {mainCard} + + ) : ( + mainCard + ); +} diff --git a/apps/portal/src/components/questions/card/QuestionCard.tsx b/apps/portal/src/components/questions/card/QuestionCard.tsx index 08c1b7be..3b4ed8c5 100644 --- a/apps/portal/src/components/questions/card/QuestionCard.tsx +++ b/apps/portal/src/components/questions/card/QuestionCard.tsx @@ -1,6 +1,6 @@ import { ChatBubbleBottomCenterTextIcon, - EyeIcon, + // EyeIcon, } from '@heroicons/react/24/outline'; import { Badge, Button } from '@tih/ui'; @@ -52,7 +52,7 @@ export type QuestionCardProps = ActionButtonProps & export default function QuestionCard({ answerCount, content, - receivedCount, + // ReceivedCount, showVoteButtons, showUserStatistics, showActionButton, @@ -62,9 +62,8 @@ export default function QuestionCard({ timestamp, role, location, - href, }: QuestionCardProps) { - const mainCard = ( + return (
{showVoteButtons && }
@@ -96,26 +95,16 @@ export default function QuestionCard({ size="sm" variant="tertiary" /> -
)}
); - - 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 ecb4eb2e..fa786917 100644 --- a/apps/portal/src/components/questions/card/QuestionOverviewCard.tsx +++ b/apps/portal/src/components/questions/card/QuestionOverviewCard.tsx @@ -1,3 +1,5 @@ +import withHref from '~/utils/questions/withHref'; + import type { QuestionCardProps } from './QuestionCard'; import QuestionCard from './QuestionCard'; @@ -14,7 +16,7 @@ export type QuestionOverviewCardProps = Omit< | 'showVoteButtons' >; -export default function QuestionOverviewCard(props: QuestionOverviewCardProps) { +function QuestionOverviewCardWithoutHref(props: QuestionOverviewCardProps) { return ( ); } + +const QuestionOverviewCard = withHref(QuestionOverviewCardWithoutHref); +export default QuestionOverviewCard;