mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-22 20:16:57 +00:00
Merge pull request #115 from TheRealOwenRees/feature/debouce
Update debounce behaviour when hovering over list items
This commit is contained in:
+1
-1
@@ -22,7 +22,7 @@ export const {
|
||||
} = atomWithDebounce<string | null>(null);
|
||||
|
||||
export const { debouncedValueAtom: debouncedHoveredListTournamentIdAtom } =
|
||||
atomWithDebounce<string | null>(null, 300, true);
|
||||
atomWithDebounce<string | null>(null, 1000, 100);
|
||||
|
||||
export const filteredTournamentsByTimeControlAtom = atom((get) => {
|
||||
const tournaments = get(tournamentsAtom);
|
||||
|
||||
@@ -3,7 +3,7 @@ import { atom, SetStateAction } from "jotai";
|
||||
export default function atomWithDebounce<T>(
|
||||
initialValue: T,
|
||||
delayMilliseconds = 500,
|
||||
shouldDebounceOnReset = false,
|
||||
delayOnResetMilliseconds = 500,
|
||||
) {
|
||||
const prevTimeoutAtom = atom<ReturnType<typeof setTimeout> | undefined>(
|
||||
undefined,
|
||||
@@ -37,14 +37,9 @@ export default function atomWithDebounce<T>(
|
||||
|
||||
onDebounceStart();
|
||||
|
||||
if (!shouldDebounceOnReset && nextValue === initialValue) {
|
||||
onDebounceEnd();
|
||||
return;
|
||||
}
|
||||
|
||||
const nextTimeoutId = setTimeout(() => {
|
||||
onDebounceEnd();
|
||||
}, delayMilliseconds);
|
||||
}, nextValue === initialValue ? delayOnResetMilliseconds : delayMilliseconds);
|
||||
|
||||
// set previous timeout atom in case it needs to get cleared
|
||||
set(prevTimeoutAtom, nextTimeoutId);
|
||||
|
||||
Reference in New Issue
Block a user