[questions][ui] improve mobile back navigation

pull/517/head
Jeff Sieu 3 years ago
parent f12c36fc4b
commit 429115a9b9

@ -0,0 +1,30 @@
import type { PropsWithChildren } from 'react';
import { ArrowSmallLeftIcon } from '@heroicons/react/24/outline';
import { Button } from '@tih/ui';
export type BackButtonLayoutProps = PropsWithChildren<{
href: string;
}>;
export default function BackButtonLayout({
href,
children,
}: BackButtonLayoutProps) {
return (
<div className="flex w-full flex-1 flex-col items-stretch gap-4 p-4 lg:flex-row">
<div>
<Button
addonPosition="start"
display="inline"
href={href}
icon={ArrowSmallLeftIcon}
label="Back"
variant="secondary"
/>
</div>
<div className="flex w-full justify-center overflow-y-auto">
{children}
</div>
</div>
);
}

@ -2,12 +2,12 @@ import Head from 'next/head';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import { useState } from 'react'; import { useState } from 'react';
import { useForm } from 'react-hook-form'; import { useForm } from 'react-hook-form';
import { ArrowSmallLeftIcon } from '@heroicons/react/24/outline';
import { Button, TextArea } from '@tih/ui'; import { Button, TextArea } from '@tih/ui';
import AnswerCommentListItem from '~/components/questions/AnswerCommentListItem'; import AnswerCommentListItem from '~/components/questions/AnswerCommentListItem';
import FullAnswerCard from '~/components/questions/card/FullAnswerCard'; import FullAnswerCard from '~/components/questions/card/FullAnswerCard';
import FullScreenSpinner from '~/components/questions/FullScreenSpinner'; import FullScreenSpinner from '~/components/questions/FullScreenSpinner';
import BackButtonLayout from '~/components/questions/layout/BackButtonLayout';
import PaginationLoadMoreButton from '~/components/questions/PaginationLoadMoreButton'; import PaginationLoadMoreButton from '~/components/questions/PaginationLoadMoreButton';
import SortOptionsSelect from '~/components/questions/SortOptionsSelect'; import SortOptionsSelect from '~/components/questions/SortOptionsSelect';
@ -104,18 +104,8 @@ export default function QuestionPage() {
{answer.content} - {APP_TITLE} {answer.content} - {APP_TITLE}
</title> </title>
</Head> </Head>
<div className="flex w-full flex-1 items-stretch pb-4"> <BackButtonLayout
<div className="flex items-baseline gap-2 py-4 pl-4"> href={`/questions/${router.query.questionId}/${router.query.questionSlug}`}>
<Button
addonPosition="start"
display="inline"
href={`/questions/${router.query.questionId}/${router.query.questionSlug}`}
icon={ArrowSmallLeftIcon}
label="Back"
variant="secondary"
/>
</div>
<div className="flex w-full justify-center overflow-y-auto py-4 px-5">
<div className="flex max-w-7xl flex-1 flex-col gap-2"> <div className="flex max-w-7xl flex-1 flex-col gap-2">
<FullAnswerCard <FullAnswerCard
answerId={answer.id} answerId={answer.id}
@ -179,8 +169,7 @@ export default function QuestionPage() {
</div> </div>
</div> </div>
</div> </div>
</div> </BackButtonLayout>
</div>
</> </>
); );
} }

@ -2,13 +2,13 @@ import Head from 'next/head';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import { useMemo, useState } from 'react'; import { useMemo, useState } from 'react';
import { useForm } from 'react-hook-form'; import { useForm } from 'react-hook-form';
import { ArrowSmallLeftIcon } from '@heroicons/react/24/outline';
import { Button, Collapsible, HorizontalDivider, TextArea } from '@tih/ui'; import { Button, Collapsible, HorizontalDivider, TextArea } from '@tih/ui';
import AnswerCommentListItem from '~/components/questions/AnswerCommentListItem'; import AnswerCommentListItem from '~/components/questions/AnswerCommentListItem';
import FullQuestionCard from '~/components/questions/card/question/FullQuestionCard'; import FullQuestionCard from '~/components/questions/card/question/FullQuestionCard';
import QuestionAnswerCard from '~/components/questions/card/QuestionAnswerCard'; import QuestionAnswerCard from '~/components/questions/card/QuestionAnswerCard';
import FullScreenSpinner from '~/components/questions/FullScreenSpinner'; import FullScreenSpinner from '~/components/questions/FullScreenSpinner';
import BackButtonLayout from '~/components/questions/layout/BackButtonLayout';
import PaginationLoadMoreButton from '~/components/questions/PaginationLoadMoreButton'; import PaginationLoadMoreButton from '~/components/questions/PaginationLoadMoreButton';
import SortOptionsSelect from '~/components/questions/SortOptionsSelect'; import SortOptionsSelect from '~/components/questions/SortOptionsSelect';
@ -182,18 +182,7 @@ export default function QuestionPage() {
{question.content} - {APP_TITLE} {question.content} - {APP_TITLE}
</title> </title>
</Head> </Head>
<div className="flex w-full flex-1 items-stretch pb-4"> <BackButtonLayout href="/questions/browse">
<div className="flex items-baseline gap-2 py-4 pl-4">
<Button
addonPosition="start"
display="inline"
href="/questions/browse"
icon={ArrowSmallLeftIcon}
label="Back"
variant="secondary"
/>
</div>
<div className="flex w-full justify-center overflow-y-auto py-4 px-5">
<div className="flex max-w-7xl flex-1 flex-col gap-2"> <div className="flex max-w-7xl flex-1 flex-col gap-2">
<div className="flex flex-col gap-2 rounded-md border bg-white p-4"> <div className="flex flex-col gap-2 rounded-md border bg-white p-4">
<FullQuestionCard <FullQuestionCard
@ -256,9 +245,7 @@ export default function QuestionPage() {
<PaginationLoadMoreButton query={commentInfiniteQuery} /> <PaginationLoadMoreButton query={commentInfiniteQuery} />
<form <form
className="mt-4" className="mt-4"
onSubmit={handleCommentSubmitClick( onSubmit={handleCommentSubmitClick(handleSubmitComment)}>
handleSubmitComment,
)}>
<TextArea <TextArea
{...commentRegister('commentContent', { {...commentRegister('commentContent', {
minLength: 1, minLength: 1,
@ -342,8 +329,7 @@ export default function QuestionPage() {
)} )}
<PaginationLoadMoreButton query={answerInfiniteQuery} /> <PaginationLoadMoreButton query={answerInfiniteQuery} />
</div> </div>
</div> </BackButtonLayout>
</div>
</> </>
); );
} }

Loading…
Cancel
Save