[questions][ui] restyle landing, question pages ()

pull/520/head
Jeff Sieu 2 years ago committed by GitHub
parent f752264101
commit e1e585df23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -25,7 +25,7 @@ export default function AnswerCommentListItem({
useAnswerCommentVote(answerCommentId); useAnswerCommentVote(answerCommentId);
return ( return (
<div className="flex gap-4 border bg-white p-2 "> <div className="flex gap-4 rounded-md border bg-white p-2">
<VotingButtons <VotingButtons
size="sm" size="sm"
upvoteCount={upvoteCount} upvoteCount={upvoteCount}

@ -20,15 +20,13 @@ export type LandingQueryData = {
companySlug: string; companySlug: string;
location: string; location: string;
questionType: QuestionsQuestionType; questionType: QuestionsQuestionType;
}; } | null;
export type LandingComponentProps = { export type LandingComponentProps = {
onLanded: (data: LandingQueryData) => void; onLanded: (data: LandingQueryData) => void;
}; };
export default function LandingComponent({ export default function LandingComponent({ onLanded }: LandingComponentProps) {
onLanded: handleLandingQuery,
}: LandingComponentProps) {
const defaultCompany = useDefaultCompany(); const defaultCompany = useDefaultCompany();
const defaultLocation = useDefaultLocation(); const defaultLocation = useDefaultLocation();
@ -70,17 +68,17 @@ export default function LandingComponent({
<main className="flex flex-1 flex-col items-center overflow-y-auto bg-white"> <main className="flex flex-1 flex-col items-center overflow-y-auto bg-white">
<div className="flex flex-1 flex-col items-start justify-center gap-12 px-4"> <div className="flex flex-1 flex-col items-start justify-center gap-12 px-4">
<header className="flex flex-col items-start gap-16"> <header className="flex flex-col items-start gap-16">
<div className="flex flex-col items-center self-stretch"> <div className="flex flex-col items-center">
<img <img
alt="Questions Bank" alt="Questions Bank"
className="h-40 w-40" className="h-40 w-40"
src="/bank-logo.png" src="/bank-logo.png"
/> />
<h1 className="text-center text-4xl font-bold text-slate-900"> <h1 className="text-primary-700 text-center text-5xl font-bold">
Tech Interview Question Bank Tech Interview Question Bank
</h1> </h1>
</div> </div>
<p className="mb-2 max-w-lg text-5xl font-semibold text-slate-900 sm:max-w-3xl"> <p className="mb-2 max-w-lg text-4xl font-semibold text-slate-900 sm:max-w-3xl">
Know the{' '} Know the{' '}
<span className="text-primary-700"> <span className="text-primary-700">
latest SWE interview questions latest SWE interview questions
@ -118,6 +116,7 @@ export default function LandingComponent({
}} }}
/> />
</div> </div>
<div className="flex items-center gap-2">
<Button <Button
addonPosition="end" addonPosition="end"
icon={ArrowSmallRightIcon} icon={ArrowSmallRightIcon}
@ -126,7 +125,7 @@ export default function LandingComponent({
variant="primary" variant="primary"
onClick={() => { onClick={() => {
if (company !== undefined && location !== undefined) { if (company !== undefined && location !== undefined) {
return handleLandingQuery({ onLanded({
companySlug: companyOptionToSlug(company), companySlug: companyOptionToSlug(company),
location: locationOptionToSlug(location), location: locationOptionToSlug(location),
questionType, questionType,
@ -134,6 +133,17 @@ export default function LandingComponent({
} }
}} }}
/> />
<Button
addonPosition="end"
icon={ArrowSmallRightIcon}
label="View all questions"
size="md"
variant="secondary"
onClick={() => {
onLanded(null);
}}
/>
</div>
</div> </div>
<div className="flex justify-center"> <div className="flex justify-center">
<iframe <iframe

@ -60,7 +60,7 @@ export default function QuestionAggregateBadge({
<Badge label={label} {...badgeProps} /> <Badge label={label} {...badgeProps} />
</button> </button>
{visible && ( {visible && (
<div ref={setTooltipRef} {...getTooltipProps()}> <div ref={setTooltipRef} {...getTooltipProps()} className="z-10">
<div className="flex flex-col gap-2 rounded-md bg-white p-2 shadow-md"> <div className="flex flex-col gap-2 rounded-md bg-white p-2 shadow-md">
<ul> <ul>
{sortedStatistics.map(({ key, value }) => ( {sortedStatistics.map(({ key, value }) => (

@ -116,6 +116,7 @@ export type BaseQuestionCardProps = ActionButtonProps &
ReceivedStatisticsProps & ReceivedStatisticsProps &
UpvoteProps & { UpvoteProps & {
content: string; content: string;
hideCard?: boolean;
questionId: string; questionId: string;
showHover?: boolean; showHover?: boolean;
timestamp: string | null; timestamp: string | null;
@ -140,6 +141,7 @@ export default function BaseQuestionCard({
actionButtonLabel, actionButtonLabel,
onActionButtonClick, onActionButtonClick,
upvoteCount, upvoteCount,
hideCard,
timestamp, timestamp,
roles, roles,
countries, countries,
@ -152,7 +154,6 @@ export default function BaseQuestionCard({
}: BaseQuestionCardProps) { }: BaseQuestionCardProps) {
const [showReceivedForm, setShowReceivedForm] = useState(false); const [showReceivedForm, setShowReceivedForm] = useState(false);
const { handleDownvote, handleUpvote, vote } = useQuestionVote(questionId); const { handleDownvote, handleUpvote, vote } = useQuestionVote(questionId);
const hoverClass = showHover ? 'hover:bg-slate-50' : '';
const locations = useMemo(() => { const locations = useMemo(() => {
if (countries === undefined) { if (countries === undefined) {
@ -185,7 +186,7 @@ export default function BaseQuestionCard({
)} )}
<div className="flex flex-1 flex-col items-start gap-2"> <div className="flex flex-1 flex-col items-start gap-2">
<div className="flex items-baseline justify-between self-stretch"> <div className="flex items-baseline justify-between self-stretch">
<div className="z-10 flex items-center gap-2 text-slate-500"> <div className="flex items-center gap-2 text-slate-500">
{showAggregateStatistics && ( {showAggregateStatistics && (
<> <>
<QuestionTypeBadge type={type} /> <QuestionTypeBadge type={type} />
@ -274,7 +275,11 @@ export default function BaseQuestionCard({
return ( return (
<article <article
className={`group flex gap-4 rounded-md border border-slate-300 bg-white p-4 ${hoverClass}`}> className={clsx(
'group flex gap-4 border-slate-300',
showHover && 'hover:bg-slate-50',
!hideCard && 'rounded-md border bg-white p-4',
)}>
{cardContent} {cardContent}
{showDeleteButton && ( {showDeleteButton && (
<div className="fill-danger-700 invisible self-center group-hover:visible"> <div className="fill-danger-700 invisible self-center group-hover:visible">

@ -28,6 +28,7 @@ export default function FullQuestionCard(props: QuestionOverviewCardProps) {
return ( return (
<BaseQuestionCard <BaseQuestionCard
{...props} {...props}
hideCard={true}
showActionButton={false} showActionButton={false}
showAddToList={true} showAddToList={true}
showAggregateStatistics={true} showAggregateStatistics={true}

@ -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,19 +182,9 @@ 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">
<FullQuestionCard <FullQuestionCard
{...question} {...question}
companies={relabeledAggregatedEncounters?.companyCounts ?? {}} companies={relabeledAggregatedEncounters?.companyCounts ?? {}}
@ -220,35 +210,15 @@ export default function QuestionPage() {
}); });
}} }}
/> />
<div className="mx-2"> <div className="ml-16 mr-2">
<Collapsible label={`View ${question.numComments} comment(s)`}> <Collapsible
<div className="mt-4 px-4"> defaultOpen={true}
<form label={
className="mb-2" <div className="text-primary-700">{`${question.numComments} comment(s)`}</div>
onSubmit={handleCommentSubmitClick(handleSubmitComment)}> }>
<TextArea <div className="">
{...commentRegister('commentContent', {
minLength: 1,
required: true,
})}
label="Post a comment"
required={true}
resize="vertical"
rows={2}
/>
<div className="my-3 flex justify-between">
<Button
disabled={!isCommentDirty || !isCommentValid}
label="Post"
type="submit"
variant="primary"
/>
</div>
</form>
{/* TODO: Add button to load more */}
<div className="flex flex-col gap-2 text-black"> <div className="flex flex-col gap-2 text-black">
<div className="flex items-center justify-between gap-2"> <div className="flex justify-end gap-2">
<p className="text-lg">Comments</p>
<div className="flex items-end gap-2"> <div className="flex items-end gap-2">
<SortOptionsSelect <SortOptionsSelect
sortOrderValue={commentSortOrder} sortOrderValue={commentSortOrder}
@ -273,22 +243,49 @@ export default function QuestionPage() {
)), )),
)} )}
<PaginationLoadMoreButton query={commentInfiniteQuery} /> <PaginationLoadMoreButton query={commentInfiniteQuery} />
<form
className="mt-4"
onSubmit={handleCommentSubmitClick(handleSubmitComment)}>
<TextArea
{...commentRegister('commentContent', {
minLength: 1,
required: true,
})}
label="Post a comment"
required={true}
resize="vertical"
rows={2}
/>
<div className="my-3 flex justify-between">
<Button
disabled={!isCommentDirty || !isCommentValid}
label="Post"
type="submit"
variant="primary"
/>
</div>
</form>
</div> </div>
</div> </div>
</Collapsible> </Collapsible>
</div> </div>
</div>
<HorizontalDivider /> <HorizontalDivider />
<form onSubmit={handleSubmit(handleSubmitAnswer)}> <form onSubmit={handleSubmit(handleSubmitAnswer)}>
<div className="flex flex-col gap-2">
<p className="text-md font-semibold">Contribute your answer</p>
<TextArea <TextArea
{...answerRegister('answerContent', { {...answerRegister('answerContent', {
minLength: 1, minLength: 1,
required: true, required: true,
})} })}
isLabelHidden={true}
label="Contribute your answer" label="Contribute your answer"
required={true} required={true}
resize="vertical" resize="vertical"
rows={5} rows={5}
/> />
</div>
<div className="mt-3 mb-1 flex justify-between"> <div className="mt-3 mb-1 flex justify-between">
<Button <Button
disabled={!isDirty || !isValid} disabled={!isDirty || !isValid}
@ -299,7 +296,9 @@ export default function QuestionPage() {
</div> </div>
</form> </form>
<div className="flex items-center justify-between gap-2"> <div className="flex items-center justify-between gap-2">
<p className="text-xl">{question.numAnswers} answers</p> <p className="text-xl font-semibold">
{question.numAnswers} answers
</p>
<div className="flex items-end gap-2"> <div className="flex items-end gap-2">
<SortOptionsSelect <SortOptionsSelect
sortOrderValue={answerSortOrder} sortOrderValue={answerSortOrder}
@ -330,8 +329,7 @@ export default function QuestionPage() {
)} )}
<PaginationLoadMoreButton query={answerInfiniteQuery} /> <PaginationLoadMoreButton query={answerInfiniteQuery} />
</div> </div>
</div> </BackButtonLayout>
</div>
</> </>
); );
} }

@ -10,6 +10,14 @@ export default function QuestionsHomePage() {
const router = useRouter(); const router = useRouter();
const handleLandingQuery = async (data: LandingQueryData) => { const handleLandingQuery = async (data: LandingQueryData) => {
if (data === null) {
// Go to browse page
router.push({
pathname: '/questions/browse',
});
return;
}
const { companySlug, location, questionType } = data; const { companySlug, location, questionType } = data;
// Go to browse page // Go to browse page

Loading…
Cancel
Save