diff --git a/apps/portal/src/components/questions/filter/FilterSection.tsx b/apps/portal/src/components/questions/filter/FilterSection.tsx index 5c515333..312122c3 100644 --- a/apps/portal/src/components/questions/filter/FilterSection.tsx +++ b/apps/portal/src/components/questions/filter/FilterSection.tsx @@ -63,22 +63,24 @@ export default function FilterSection< /> )} {isSingleSelect ? ( - option.checked)?.value} - onChange={(value) => { - onOptionChange(value); - }}> - {options.map((option) => ( - - ))} - +
+ option.checked)?.value} + onChange={(value) => { + onOptionChange(value); + }}> + {options.map((option) => ( + + ))} + +
) : ( -
+
{options.map((option) => ( { + const handleLandingQuery = async (data: LandingQueryData) => { const { company, location, questionType } = data; + setSelectedCompanies([company]); setSelectedLocations([location]); setSelectedQuestionTypes([questionType as QuestionsQuestionType]); @@ -142,11 +143,15 @@ export default function QuestionsHomePage() { areLocationsInitialized, ]); + const { pathname } = router; + useEffect(() => { - if (areFiltersInitialized && !loaded) { - // Update query params - router.replace({ - pathname: router.pathname, + if (areFiltersInitialized) { + // Router.replace used instead of router.replace to avoid + // the page reloading itself since the router.replace + // callback changes on every page load + Router.replace({ + pathname, query: { companies: selectedCompanies, locations: selectedLocations, @@ -169,7 +174,7 @@ export default function QuestionsHomePage() { areFiltersInitialized, hasLanded, loaded, - router, + pathname, selectedCompanies, selectedLocations, selectedQuestionAge, @@ -181,7 +186,7 @@ export default function QuestionsHomePage() { } const filterSidebar = ( -
+
( (newFilters: Array) => { setFilters(newFilters); localStorage.setItem(name, JSON.stringify(newFilters)); - router.replace({ - pathname: router.pathname, - query: { - ...router.query, - [name]: newFilters, - }, - }); }, - [name, router], + [name], ); return [filters, setFiltersCallback, isInitialized] as const; @@ -66,9 +59,7 @@ export const useSearchFilterSingle = ( return [ filters[0], - (value: Value) => { - setFilters([value]); - }, + (value: Value) => setFilters([value]), isInitialized, ] as const; };