mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-19 22:46:20 -05:00
Debouncing search estimate.
This commit is contained in:
parent
f37e598c53
commit
d042b06e8b
1 changed files with 9 additions and 1 deletions
|
|
@ -5,6 +5,7 @@ import {usePages, useQuery} from "../hooks/customHooks";
|
|||
import {ZimSearchView} from "./Zim";
|
||||
import {searchEstimate, searchSuggestions} from "../api";
|
||||
import {normalizeEstimate, TabLinks} from "./Common";
|
||||
import _ from "lodash";
|
||||
|
||||
export function useSearchSuggestions() {
|
||||
const {searchParams} = useQuery();
|
||||
|
|
@ -28,11 +29,14 @@ export function useSearchSuggestions() {
|
|||
})
|
||||
},
|
||||
};
|
||||
console.debug('newSuggestions', newSuggestions);
|
||||
setSuggestions(newSuggestions);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
console.error('Failed to get search suggestions');
|
||||
}
|
||||
} else {
|
||||
setSuggestions(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -127,8 +131,12 @@ export const useSearchEstimate = (search_str, activeTags) => {
|
|||
}
|
||||
}
|
||||
|
||||
const debouncedEstimate = _.debounce(async () => await localFetchSearchEstimate(), 800);
|
||||
|
||||
useEffect(() => {
|
||||
localFetchSearchEstimate();
|
||||
debouncedEstimate();
|
||||
|
||||
return () => debouncedEstimate.cancel();
|
||||
}, [search_str, JSON.stringify(activeTags)]);
|
||||
|
||||
return {fileGroups, zimsSum, zims}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue