From 16093555441b5403b58a8eb6b53ed69cb574cc34 Mon Sep 17 00:00:00 2001 From: Jeff Sieu Date: Sat, 22 Oct 2022 15:10:40 +0800 Subject: [PATCH] [questions][ui] revamp landing page look --- .../components/questions/LandingComponent.tsx | 139 +++++++++++------- .../questions/filter/FilterSection.tsx | 9 +- .../forms/ContributeQuestionForm.tsx | 4 - .../forms/CreateQuestionEncounterForm.tsx | 4 - .../questions/typeahead/LocationTypeahead.tsx | 4 +- .../questions/typeahead/RoleTypeahead.tsx | 4 +- .../src/utils/questions/useDefaultCompany.ts | 22 +++ .../src/utils/questions/useDefaultLocation.ts | 7 + 8 files changed, 128 insertions(+), 65 deletions(-) create mode 100644 apps/portal/src/utils/questions/useDefaultCompany.ts create mode 100644 apps/portal/src/utils/questions/useDefaultLocation.ts diff --git a/apps/portal/src/components/questions/LandingComponent.tsx b/apps/portal/src/components/questions/LandingComponent.tsx index 7f3ffee4..e4de4b9e 100644 --- a/apps/portal/src/components/questions/LandingComponent.tsx +++ b/apps/portal/src/components/questions/LandingComponent.tsx @@ -1,13 +1,15 @@ -import { useState } from 'react'; +import { useEffect, useState } from 'react'; import { ArrowSmallRightIcon } from '@heroicons/react/24/outline'; import type { QuestionsQuestionType } from '@prisma/client'; import { Button, Select } from '@tih/ui'; -import { - COMPANIES, - LOCATIONS, - QUESTION_TYPES, -} from '~/utils/questions/constants'; +import { QUESTION_TYPES } from '~/utils/questions/constants'; +import useDefaultCompany from '~/utils/questions/useDefaultCompany'; +import useDefaultLocation from '~/utils/questions/useDefaultLocation'; + +import type { FilterChoice } from './filter/FilterSection'; +import CompanyTypeahead from './typeahead/CompanyTypeahead'; +import LocationTypeahead from './typeahead/LocationTypeahead'; export type LandingQueryData = { company: string; @@ -22,76 +24,109 @@ export type LandingComponentProps = { export default function LandingComponent({ onLanded: handleLandingQuery, }: LandingComponentProps) { - const [landingQueryData, setLandingQueryData] = useState({ - company: 'Google', - location: 'Singapore', - questionType: 'CODING', - }); + const defaultCompany = useDefaultCompany(); + const defaultLocation = useDefaultLocation(); + + const [company, setCompany] = useState( + defaultCompany, + ); + const [location, setLocation] = useState( + defaultLocation, + ); + + const [questionType, setQuestionType] = + useState('CODING'); - const handleChangeCompany = (company: string) => { - setLandingQueryData((prev) => ({ ...prev, company })); + const handleChangeCompany = (newCompany: FilterChoice) => { + setCompany(newCompany); }; - const handleChangeLocation = (location: string) => { - setLandingQueryData((prev) => ({ ...prev, location })); + const handleChangeLocation = (newLocation: FilterChoice) => { + setCompany(newLocation); }; - const handleChangeType = (questionType: QuestionsQuestionType) => { - setLandingQueryData((prev) => ({ ...prev, questionType })); + const handleChangeType = (newQuestionType: QuestionsQuestionType) => { + setQuestionType(newQuestionType); }; - return ( -
-
-
-
- app logo -

- Tech Interview Question Bank -

-
-

- Get to know the latest SWE interview questions asked by top companies -

+ useEffect(() => { + if (company === undefined) { + setCompany(defaultCompany); + } + }, [defaultCompany, company]); + + useEffect(() => { + if (location !== undefined) { + setLocation(defaultLocation); + } + }, [defaultLocation, location]); -
-

Find

-
+ return ( +
+
+
+
+

+ Tech Interview Question Bank +

+ app logo +
+

+ Know the{' '} + + latest SWE interview questions + {' '} + asked by top companies. +

+
+
+

Find questions

+
+

about

-

in

-