From 84710209f38ccaafeeb3ef56ce170e871549aba7 Mon Sep 17 00:00:00 2001 From: Wu Peirong Date: Sun, 30 Oct 2022 12:42:09 +0800 Subject: [PATCH] [resumes][feat] persist filter disclosure opening --- apps/portal/src/pages/resumes/[resumeId].tsx | 5 + apps/portal/src/pages/resumes/index.tsx | 164 +++++++++++-------- 2 files changed, 102 insertions(+), 67 deletions(-) diff --git a/apps/portal/src/pages/resumes/[resumeId].tsx b/apps/portal/src/pages/resumes/[resumeId].tsx index 7af32460..3c0604b4 100644 --- a/apps/portal/src/pages/resumes/[resumeId].tsx +++ b/apps/portal/src/pages/resumes/[resumeId].tsx @@ -142,6 +142,11 @@ export default function ResumeReviewPage() { pathname: '/resumes', query: { currentPage: JSON.stringify(1), + isFiltersOpen: JSON.stringify({ + experience: experienceLabel !== undefined, + location: locationLabel !== undefined, + role: roleLabel !== undefined, + }), searchValue: JSON.stringify(''), shortcutSelected: JSON.stringify('all'), sortOrder: JSON.stringify('latest'), diff --git a/apps/portal/src/pages/resumes/index.tsx b/apps/portal/src/pages/resumes/index.tsx index 5bcd2291..db14977f 100644 --- a/apps/portal/src/pages/resumes/index.tsx +++ b/apps/portal/src/pages/resumes/index.tsx @@ -127,6 +127,13 @@ export default function ResumeHomePage() { 'userFilters', INITIAL_FILTER_STATE, ); + const [isFiltersOpen, setIsFiltersOpen, isFiltersOpenInit] = useSearchParams< + Record + >('isFiltersOpen', { + experience: false, + location: false, + role: false, + }); const [mobileFiltersOpen, setMobileFiltersOpen] = useState(false); const skip = (currentPage - 1) * PAGE_LIMIT; @@ -137,7 +144,8 @@ export default function ResumeHomePage() { isSearchValueInit && isShortcutInit && isCurrentPageInit && - isUserFiltersInit + isUserFiltersInit && + isFiltersOpenInit ); }, [ isTabsValueInit, @@ -146,6 +154,7 @@ export default function ResumeHomePage() { isShortcutInit, isCurrentPageInit, isUserFiltersInit, + isFiltersOpenInit, ]); useEffect(() => { @@ -164,6 +173,7 @@ export default function ResumeHomePage() { pathname: router.pathname, query: { currentPage: JSON.stringify(currentPage), + isFiltersOpen: JSON.stringify(isFiltersOpen), searchValue: JSON.stringify(searchValue), shortcutSelected: JSON.stringify(shortcutSelected), sortOrder: JSON.stringify(sortOrder), @@ -180,6 +190,7 @@ export default function ResumeHomePage() { currentPage, router.pathname, isSearchOptionsInit, + isFiltersOpen, ]); const allResumesQuery = trpc.useQuery( @@ -399,11 +410,19 @@ export default function ResumeHomePage() { + className="border-t border-slate-200 px-4 pt-6 pb-4" + defaultOpen={isFiltersOpen[filter.id]}> {({ open }) => ( <>

- + + setIsFiltersOpen({ + ...isFiltersOpen, + [filter.id]: !isFiltersOpen[filter.id], + }) + }> {filter.label} @@ -496,72 +515,83 @@ export default function ResumeHomePage() {

Explore these filters

- {filters.map((filter) => ( - - {({ open }) => ( - <> -

- - - {filter.label} - - - {open ? ( - - -

- - - {filter.options.map((option) => ( -
- - onFilterCheckboxChange( - isChecked, - filter.id, + {isFiltersOpenInit && + filters.map((filter) => ( + + {({ open }) => ( + <> +

+ + setIsFiltersOpen({ + ...isFiltersOpen, + [filter.id]: !isFiltersOpen[filter.id], + }) + }> + + {filter.label} + + + {open ? ( + + +

+ + + {filter.options.map((option) => ( +
+ + onFilterCheckboxChange( + isChecked, + filter.id, + option.value, + ) + } + /> + + ( + {getFilterCount(filter.label, option.label)} ) - } - /> - - ({getFilterCount(filter.label, option.label)}) - -
- ))} -
-

onClearFilterClick(filter.id)}> - Clear -

-
- - )} -
- ))} + +
+ ))} +
+

onClearFilterClick(filter.id)}> + Clear +

+
+ + )} +
+ ))}