diff --git a/components/Common/Search/States/WithSearchBox.tsx b/components/Common/Search/States/WithSearchBox.tsx index 685650aedc90..273391c18f88 100644 --- a/components/Common/Search/States/WithSearchBox.tsx +++ b/components/Common/Search/States/WithSearchBox.tsx @@ -71,7 +71,9 @@ export const WithSearchBox: FC = ({ onClose }) => { }, []); useEffect( - () => debounce(() => search(searchTerm), 1000), + () => { + debounce(() => search(searchTerm), 1000)(); + }, // we don't need to care about memoization of search function // eslint-disable-next-line react-hooks/exhaustive-deps [searchTerm, selectedFacet] @@ -100,7 +102,12 @@ export const WithSearchBox: FC = ({ onClose }) => { }; const facets: Facets = { - all: searchResults?.count ?? 0, + all: searchResults?.facets + ? Object.values(searchResults?.facets.siteSection.values).reduce( + (a, b) => a + b, + 0 + ) + : 0, ...(searchResults?.facets?.siteSection?.values ?? {}), }; diff --git a/util/debounce.ts b/util/debounce.ts index 73472b35e07e..ca569ba359e9 100644 --- a/util/debounce.ts +++ b/util/debounce.ts @@ -1,16 +1,16 @@ type DebounceFunction = (...args: Array) => void; -export const debounce = ( - func: T, - delay: number -): ((...args: Parameters) => void) => { - let timeoutId: NodeJS.Timeout; +let timeoutId: NodeJS.Timeout; - return (...args: Parameters) => { +export const debounce = + ( + func: T, + delay: number + ): ((...args: Parameters) => void) => + (...args: Parameters) => { clearTimeout(timeoutId); timeoutId = setTimeout(() => { func(...args); }, delay); }; -};