mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-23 21:44:55 +03:00
fix: adding debounce to search
This commit is contained in:
parent
54c6b1f1af
commit
f67395c94c
@ -20,6 +20,7 @@ import { Pagination } from "./pagination";
|
|||||||
import { useCatalogue } from "@renderer/hooks/use-catalogue";
|
import { useCatalogue } from "@renderer/hooks/use-catalogue";
|
||||||
import { GameItem } from "./game-item";
|
import { GameItem } from "./game-item";
|
||||||
import { FilterItem } from "./filter-item";
|
import { FilterItem } from "./filter-item";
|
||||||
|
import { debounce } from "lodash-es";
|
||||||
|
|
||||||
const filterCategoryColors = {
|
const filterCategoryColors = {
|
||||||
genres: "hsl(262deg 50% 47%)",
|
genres: "hsl(262deg 50% 47%)",
|
||||||
@ -58,26 +59,36 @@ export default function Catalogue() {
|
|||||||
|
|
||||||
const { getRepacksForObjectId } = useRepacks();
|
const { getRepacksForObjectId } = useRepacks();
|
||||||
|
|
||||||
|
const debouncedSearch = useRef(
|
||||||
|
debounce(async (filters, pageSize, offset) => {
|
||||||
|
const abortController = new AbortController();
|
||||||
|
abortControllerRef.current = abortController;
|
||||||
|
|
||||||
|
const response = await window.electron.searchGames(
|
||||||
|
filters,
|
||||||
|
pageSize,
|
||||||
|
offset
|
||||||
|
);
|
||||||
|
|
||||||
|
if (abortController.signal.aborted) return;
|
||||||
|
|
||||||
|
setResults(response.edges);
|
||||||
|
setItemsCount(response.count);
|
||||||
|
setIsLoading(false);
|
||||||
|
}, 500)
|
||||||
|
).current;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setResults([]);
|
setResults([]);
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
abortControllerRef.current?.abort();
|
abortControllerRef.current?.abort();
|
||||||
|
|
||||||
const abortController = new AbortController();
|
debouncedSearch(filters, PAGE_SIZE, (page - 1) * PAGE_SIZE);
|
||||||
abortControllerRef.current = abortController;
|
|
||||||
|
|
||||||
window.electron
|
return () => {
|
||||||
.searchGames(filters, PAGE_SIZE, (page - 1) * PAGE_SIZE)
|
debouncedSearch.cancel();
|
||||||
.then((response) => {
|
};
|
||||||
if (abortController.signal.aborted) {
|
}, [filters, page, debouncedSearch]);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setResults(response.edges);
|
|
||||||
setItemsCount(response.count);
|
|
||||||
setIsLoading(false);
|
|
||||||
});
|
|
||||||
}, [filters, page, dispatch]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
downloadSourcesTable.toArray().then((sources) => {
|
downloadSourcesTable.toArray().then((sources) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user