From 8299a5463ed7ce3220452b77c0b0f729a192599c Mon Sep 17 00:00:00 2001 From: Yangshun Tay Date: Wed, 9 Nov 2022 07:15:44 +0800 Subject: [PATCH] [questions][feat] tweak cards UI (#546) * [questions][feat] tweak card UI * [questions][feat] tweak comment and answer pages --- .../questions/AddToListDropdown.tsx | 2 +- .../questions/QuestionAggregateBadge.tsx | 23 ++-- .../questions/SortOptionsSelect.tsx | 4 +- .../components/questions/VotingButtons.tsx | 56 ++++---- .../components/questions/card/AnswerCard.tsx | 50 +++++--- .../card/question/BaseQuestionCard.tsx | 92 ++++++-------- .../questions/comments/CommentListItem.tsx | 22 ++-- .../forms/CreateQuestionEncounterForm.tsx | 3 + .../questions/layout/BackButtonLayout.tsx | 7 +- .../questions/typeahead/ExpandedTypeahead.tsx | 3 +- .../answer/[answerId]/[answerSlug]/index.tsx | 8 +- .../[questionId]/[questionSlug]/index.tsx | 120 +++++++++--------- apps/portal/src/pages/questions/browse.tsx | 2 +- 13 files changed, 212 insertions(+), 180 deletions(-) diff --git a/apps/portal/src/components/questions/AddToListDropdown.tsx b/apps/portal/src/components/questions/AddToListDropdown.tsx index 039edd7e..d238bd6e 100644 --- a/apps/portal/src/components/questions/AddToListDropdown.tsx +++ b/apps/portal/src/components/questions/AddToListDropdown.tsx @@ -106,7 +106,7 @@ export default function AddToListDropdown({ const CustomMenuButton = ({ children }: PropsWithChildren) => ( {visible && (
diff --git a/apps/portal/src/components/questions/SortOptionsSelect.tsx b/apps/portal/src/components/questions/SortOptionsSelect.tsx index 14e2d841..f9e8fa5a 100644 --- a/apps/portal/src/components/questions/SortOptionsSelect.tsx +++ b/apps/portal/src/components/questions/SortOptionsSelect.tsx @@ -36,7 +36,7 @@ export default function SortOptionsSelect({ return (
-
+
{ onUpvote(); }); @@ -44,31 +38,45 @@ export default function VotingButtons({ return (
-

{upvoteCount}

-
); } diff --git a/apps/portal/src/components/questions/card/AnswerCard.tsx b/apps/portal/src/components/questions/card/AnswerCard.tsx index 256dc3e9..63bfec31 100644 --- a/apps/portal/src/components/questions/card/AnswerCard.tsx +++ b/apps/portal/src/components/questions/card/AnswerCard.tsx @@ -1,4 +1,5 @@ -import { format } from 'date-fns'; +import clsx from 'clsx'; +import { formatDistanceToNow } from 'date-fns'; import { ChatBubbleLeftRightIcon } from '@heroicons/react/24/outline'; import useAnswerVote from '~/utils/questions/vote/useAnswerVote'; @@ -30,11 +31,13 @@ export default function AnswerCard({ showHover, }: AnswerCardProps) { const { handleUpvote, handleDownvote, vote } = useAnswerVote(answerId); - const hoverClass = showHover ? 'hover:bg-slate-50' : ''; return (
+ className={clsx( + 'flex gap-4 rounded-md border border-slate-200 bg-white p-4 sm:rounded-lg', + showHover && 'hover:bg-slate-50', + )}> -
+
{`${authorName} -

{authorName}

-

- Posted on: {format(createdAt, 'h:mm a, MMMM dd, yyyy')} + alt={authorName} + className="h-7 w-7 rounded-full" + src={authorImageUrl} + /> +

{authorName}

+ · +

+ {formatDistanceToNow(createdAt, { + addSuffix: true, + })}

-

{content}

- {commentCount !== undefined && ( -
- -

+

{content}

+
+ {commentCount !== undefined && ( +
- )} + + )} +
); diff --git a/apps/portal/src/components/questions/card/question/BaseQuestionCard.tsx b/apps/portal/src/components/questions/card/question/BaseQuestionCard.tsx index 2e7eff53..0ebe99fe 100644 --- a/apps/portal/src/components/questions/card/question/BaseQuestionCard.tsx +++ b/apps/portal/src/components/questions/card/question/BaseQuestionCard.tsx @@ -1,5 +1,10 @@ import clsx from 'clsx'; import { useMemo, useState } from 'react'; +import { + BuildingOfficeIcon, + MapPinIcon, + UserCircleIcon, +} from '@heroicons/react/20/solid'; import { ChatBubbleBottomCenterTextIcon, CheckIcon, @@ -198,21 +203,24 @@ export default function BaseQuestionCard({
)} -
-
-
+
+
+
{showAggregateStatistics && ( <> - + )} {timestamp !== null && ( @@ -240,59 +248,43 @@ export default function BaseQuestionCard({

{content}

+ {!showReceivedForm && (showAnswerStatistics || showReceivedStatistics || showCreateEncounterButton) && ( -
+
{showAnswerStatistics && ( - <> -
-
-
-
- + {answerCount} {answerCount === 1 ? 'answer' : 'answers'} + +
)} {showReceivedStatistics && ( - <> -
-
-
-
- +
+ +
)} {showCreateEncounterButton && (
{children}
-
+ ); } diff --git a/apps/portal/src/components/questions/typeahead/ExpandedTypeahead.tsx b/apps/portal/src/components/questions/typeahead/ExpandedTypeahead.tsx index f624f69d..7d56ea20 100644 --- a/apps/portal/src/components/questions/typeahead/ExpandedTypeahead.tsx +++ b/apps/portal/src/components/questions/typeahead/ExpandedTypeahead.tsx @@ -44,11 +44,12 @@ export default function ExpandedTypeahead({ ); return ( -
+
{suggestions.map((suggestion) => (
-
+

Comments

diff --git a/apps/portal/src/pages/questions/[questionId]/[questionSlug]/index.tsx b/apps/portal/src/pages/questions/[questionId]/[questionSlug]/index.tsx index 0e981294..c526a9be 100644 --- a/apps/portal/src/pages/questions/[questionId]/[questionSlug]/index.tsx +++ b/apps/portal/src/pages/questions/[questionId]/[questionSlug]/index.tsx @@ -200,8 +200,8 @@ export default function QuestionPage() { -
-
+
+
-
+
{`${question.numComments} comment(s)`}
}> -
-
-
-
- -
+
+
+
+
+
+
{(commentData?.pages ?? []).flatMap(({ data: comments }) => comments.map((comment) => ( )), )} - -
-