From 7a2886f876787a1e1ab66060e1eeb40849bea600 Mon Sep 17 00:00:00 2001 From: Jeff Sieu Date: Tue, 25 Oct 2022 01:17:18 +0800 Subject: [PATCH] [questions][fix] fix search params loading wrongly --- .../components/questions/LandingComponent.tsx | 2 +- apps/portal/src/pages/questions/browse.tsx | 92 +++++++++---------- .../src/utils/questions/useSearchParam.ts | 22 ++--- 3 files changed, 58 insertions(+), 58 deletions(-) diff --git a/apps/portal/src/components/questions/LandingComponent.tsx b/apps/portal/src/components/questions/LandingComponent.tsx index 1007f1e4..cd2ace15 100644 --- a/apps/portal/src/components/questions/LandingComponent.tsx +++ b/apps/portal/src/components/questions/LandingComponent.tsx @@ -118,7 +118,7 @@ export default function LandingComponent({ onClick={() => { if (company !== undefined && location !== undefined) { return handleLandingQuery({ - company: company.value, + company: company.label, location: location.value, questionType, }); diff --git a/apps/portal/src/pages/questions/browse.tsx b/apps/portal/src/pages/questions/browse.tsx index cb895f27..37193635 100644 --- a/apps/portal/src/pages/questions/browse.tsx +++ b/apps/portal/src/pages/questions/browse.tsx @@ -9,7 +9,6 @@ import { Button, SlideOut } from '@tih/ui'; import QuestionOverviewCard from '~/components/questions/card/question/QuestionOverviewCard'; import ContributeQuestionCard from '~/components/questions/ContributeQuestionCard'; -import type { FilterOption } from '~/components/questions/filter/FilterSection'; import FilterSection from '~/components/questions/filter/FilterSection'; import QuestionSearchBar from '~/components/questions/QuestionSearchBar'; import CompanyTypeahead from '~/components/questions/typeahead/CompanyTypeahead'; @@ -195,17 +194,17 @@ export default function QuestionsBrowsePage() { const [loaded, setLoaded] = useState(false); const [filterDrawerOpen, setFilterDrawerOpen] = useState(false); - const [selectedCompanyOptions, setSelectedCompanyOptions] = useState< - Array - >([]); + // Const [selectedCompanyOptions, setSelectedCompanyOptions] = useState< + // Array + // >([]); - const [selectedRoleOptions, setSelectedRoleOptions] = useState< - Array - >([]); + // const [selectedRoleOptions, setSelectedRoleOptions] = useState< + // Array + // >([]); - const [selectedLocationOptions, setSelectedLocationOptions] = useState< - Array - >([]); + // const [selectedLocationOptions, setSelectedLocationOptions] = useState< + // Array + // >([]); const questionTypeFilterOptions = useMemo(() => { return QUESTION_TYPES.map((questionType) => ({ @@ -275,9 +274,37 @@ export default function QuestionsBrowsePage() { sortType, ]); + const selectedCompanyOptions = useMemo(() => { + return selectedCompanies.map((company) => ({ + checked: true, + id: company, + label: company, + value: company, + })); + }, [selectedCompanies]); + + const selectedRoleOptions = useMemo(() => { + return selectedRoles.map((role) => ({ + checked: true, + id: role, + label: role, + value: role, + })); + }, [selectedRoles]); + + const selectedLocationOptions = useMemo(() => { + return selectedLocations.map((location) => ({ + checked: true, + id: location, + label: location, + value: location, + })); + }, [selectedLocations]); + if (!loaded) { return null; } + const filterSidebar = (