From f955ced1d60656bc1ce1a441aebcdba04cca73c3 Mon Sep 17 00:00:00 2001 From: himaniraghav3 Date: Wed, 29 Apr 2026 14:04:32 +0530 Subject: [PATCH 1/4] Add debounce for filters and reorder filters --- .../TalentSearchPage/TalentSearchPage.tsx | 87 +++++++++++++------ 1 file changed, 60 insertions(+), 27 deletions(-) diff --git a/src/apps/customer-portal/src/pages/talent-search/TalentSearchPage/TalentSearchPage.tsx b/src/apps/customer-portal/src/pages/talent-search/TalentSearchPage/TalentSearchPage.tsx index e4b3f07fd..8e9f37e0a 100644 --- a/src/apps/customer-portal/src/pages/talent-search/TalentSearchPage/TalentSearchPage.tsx +++ b/src/apps/customer-portal/src/pages/talent-search/TalentSearchPage/TalentSearchPage.tsx @@ -32,7 +32,9 @@ type TalentSearchSortOption = 'alphabetical' | 'matching-index' export const TalentSearchPage: FC = () => { const skipNextAutoSearchRef = useRef(false) - const searchGenerationRef = useRef(0) // ← add this + const searchGenerationRef = useRef(0) + const toggleDebounceTimerRef = useRef | null>(null) + const pendingToggleAutoSearchRef = useRef(false) const [lastSearchedDescription, setLastSearchedDescription] = useState('') const countryLookup: CountryLookup[] | undefined = useCountryLookup() @@ -91,20 +93,8 @@ export const TalentSearchPage: FC = () => { [hasSkillSearch], ) - const filteredResults = useMemo(() => results.filter(talent => { - if (onlyActive && !talent.isRecentlyActive) { - return false - } - - if (onlyOpenToWork && !talent.openToWork) { - return false - } - - return true - }), [onlyActive, onlyOpenToWork, results]) - // Order comes from reports-api (sortBy/sortOrder on each request) so pagination stays globally consistent. - const displayedResults = filteredResults + const displayedResults = results const foundMembersCount = totalResults || displayedResults.length const displayedResultsWithCountryName = useMemo( @@ -162,6 +152,7 @@ export const TalentSearchPage: FC = () => { }, ): Promise => { const append = overrides?.append === true + const countries = (overrides?.countries ?? selectedCountryCodesList) .filter(Boolean) const generation = overrides?.generation @@ -345,15 +336,47 @@ export const TalentSearchPage: FC = () => { useEffect(() => { if ((shouldShowIntroState) || isExtractingSkills) { + if (toggleDebounceTimerRef.current) { + clearTimeout(toggleDebounceTimerRef.current) + } + + pendingToggleAutoSearchRef.current = false + return } if (skipNextAutoSearchRef.current) { skipNextAutoSearchRef.current = false + if (toggleDebounceTimerRef.current) { + clearTimeout(toggleDebounceTimerRef.current) + } + + pendingToggleAutoSearchRef.current = false + return } - runMemberSearch(selectedSkills, { generation: searchGenerationRef.current, page: 1 }) + const runSearch = (): void => { + runMemberSearch(selectedSkills, { + generation: searchGenerationRef.current, + page: 1, + }) + } + + // Throttle auto-search on checkbox toggles to avoid multiple overlapping requests. + if (pendingToggleAutoSearchRef.current) { + pendingToggleAutoSearchRef.current = false + + if (toggleDebounceTimerRef.current) { + clearTimeout(toggleDebounceTimerRef.current) + } + + toggleDebounceTimerRef.current = setTimeout(() => { + runSearch() + }, 800) + } else { + runSearch() + } }, [ hasSearched, hasActiveFilters, @@ -366,6 +389,13 @@ export const TalentSearchPage: FC = () => { shouldShowIntroState, ]) + // Cleanup any pending debounced request on unmount. + useEffect(() => (): void => { + if (toggleDebounceTimerRef.current) { + clearTimeout(toggleDebounceTimerRef.current) + } + }, []) + const handleLoadMore = useCallback((): void => { if (isLoadingMore || isSearchingMembers || !hasMoreResults) { return @@ -472,24 +502,13 @@ export const TalentSearchPage: FC = () => { placeholder='Select country' /> - +