Update debounce behaviour when hovering over list items

This commit is contained in:
Timothy Armes
2023-07-20 08:50:34 +02:00
parent 6baa63c23d
commit 70b685fa99
2 changed files with 3 additions and 8 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ export const {
} = atomWithDebounce<string | null>(null); } = atomWithDebounce<string | null>(null);
export const { debouncedValueAtom: debouncedHoveredListTournamentIdAtom } = export const { debouncedValueAtom: debouncedHoveredListTournamentIdAtom } =
atomWithDebounce<string | null>(null, 300, true); atomWithDebounce<string | null>(null, 1000, 100);
export const filteredTournamentsByTimeControlAtom = atom((get) => { export const filteredTournamentsByTimeControlAtom = atom((get) => {
const tournaments = get(tournamentsAtom); const tournaments = get(tournamentsAtom);
+2 -7
View File
@@ -3,7 +3,7 @@ import { atom, SetStateAction } from "jotai";
export default function atomWithDebounce<T>( export default function atomWithDebounce<T>(
initialValue: T, initialValue: T,
delayMilliseconds = 500, delayMilliseconds = 500,
shouldDebounceOnReset = false, delayOnResetMilliseconds = 500,
) { ) {
const prevTimeoutAtom = atom<ReturnType<typeof setTimeout> | undefined>( const prevTimeoutAtom = atom<ReturnType<typeof setTimeout> | undefined>(
undefined, undefined,
@@ -37,14 +37,9 @@ export default function atomWithDebounce<T>(
onDebounceStart(); onDebounceStart();
if (!shouldDebounceOnReset && nextValue === initialValue) {
onDebounceEnd();
return;
}
const nextTimeoutId = setTimeout(() => { const nextTimeoutId = setTimeout(() => {
onDebounceEnd(); onDebounceEnd();
}, delayMilliseconds); }, nextValue === initialValue ? delayOnResetMilliseconds : delayMilliseconds);
// set previous timeout atom in case it needs to get cleared // set previous timeout atom in case it needs to get cleared
set(prevTimeoutAtom, nextTimeoutId); set(prevTimeoutAtom, nextTimeoutId);