This commit is contained in:
Simon Knott 2025-01-17 12:19:44 +01:00
parent ef9f0ffd69
commit b4d900f9bf
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC

View file

@ -235,18 +235,16 @@ export const kWebLinkRe = new RegExp('(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\\/\\/|www\\
export function useFlash(): [boolean, EffectCallback] {
const [flash, setFlash] = React.useState(false);
const trigger = React.useCallback<React.EffectCallback>(() => {
let timeout: number | undefined;
const timeouts: any[] = [];
setFlash(currentlyFlashing => {
if (!currentlyFlashing) {
timeout = setTimeout(() => setFlash(false), 1000) as any;
timeouts.push(setTimeout(() => setFlash(false), 1000));
if (!currentlyFlashing)
return true;
}
// It's already flashing, so we remove the class and re-add it after 50ms to trigger the animation again.
timeout = setTimeout(() => setFlash(true), 50) as any;
timeouts.push(setTimeout(() => setFlash(true), 50));
return false;
});
return () => clearTimeout(timeout);
return () => timeouts.forEach(clearTimeout);
}, [setFlash]);
return [flash, trigger];
}