mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-23 04:26: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);
|
} = 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);
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user