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

-