From 0ccdcec03950d23aaaea2c143394d9a2bc3509ca Mon Sep 17 00:00:00 2001 From: Aprillion Date: Sat, 16 Sep 2023 09:55:23 +0200 Subject: [PATCH] fix search * use state for re-render * use ref for current query detection in closure functions from previous render * queue wasn't enough, change to manual debounce of searchLater * add console debug to check after deployment --- app/components/search.tsx | 8 ++--- app/hooks/search.tsx | 74 +++++++++++++++------------------------ 2 files changed, 33 insertions(+), 49 deletions(-) diff --git a/app/components/search.tsx b/app/components/search.tsx index 1d79f7b9..de6e9112 100644 --- a/app/components/search.tsx +++ b/app/components/search.tsx @@ -37,7 +37,7 @@ export default function Search({ const [urlSearchParams] = useSearchParams() const placeholder = urlSearchParams.get('placeholder') ?? 'Search for more questions here...' - const {search, arePendingSearches, results} = useSearch(onSiteAnswersRef, limitFromUrl) + const {search, isPendingSearch, results} = useSearch(onSiteAnswersRef, limitFromUrl) const searchFn = (rawValue: string) => { const value = rawValue.trim() @@ -108,8 +108,8 @@ export default function Search({ /> -
- {arePendingSearches && results.length == 0 && ( +
+ {isPendingSearch && results.length == 0 && (
Searching for questions...
)} @@ -135,7 +135,7 @@ export default function Search({ }} /> ))} - {showResults && results.length === 0 && !arePendingSearches && (no results)} + {showResults && results.length === 0 && !isPendingSearch && (no results)} {!queryFromUrl && (