0
0
Fork 0

Change hover cards to not appear until the mouse stops in web UI (#30850)

This commit is contained in:
Eugen Rochko 2024-07-01 17:52:01 +02:00 committed by GitHub
parent 20fa9ce484
commit b728c0e8ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 131 additions and 55 deletions

View file

@ -2,19 +2,34 @@ import { useRef, useCallback, useEffect } from 'react';
export const useTimeout = () => {
const timeoutRef = useRef<ReturnType<typeof setTimeout>>();
const callbackRef = useRef<() => void>();
const set = useCallback((callback: () => void, delay: number) => {
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}
callbackRef.current = callback;
timeoutRef.current = setTimeout(callback, delay);
}, []);
const delay = useCallback((delay: number) => {
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
}
if (!callbackRef.current) {
return;
}
timeoutRef.current = setTimeout(callbackRef.current, delay);
}, []);
const cancel = useCallback(() => {
if (timeoutRef.current) {
clearTimeout(timeoutRef.current);
timeoutRef.current = undefined;
callbackRef.current = undefined;
}
}, []);
@ -25,5 +40,5 @@ export const useTimeout = () => {
[cancel],
);
return [set, cancel] as const;
return [set, cancel, delay] as const;
};