"Saved" is a moment, top-right, and gone in five seconds
it was a permanent line under the controls saying "Saved." — which said nothing, because everything on this screen has been saved, all the time. it looked exactly like feedback, so the one moment it actually meant something was indistinguishable from every moment it did not. now it appears when a save LANDS and clears itself. top-right of the block, beside the title rather than in the flow: it is a remark about the block, not part of what you are doing, and inline it pushes everything below down a line and then pulls it back up — a layout that jumps every time somebody saves. "Not set yet" stays. that IS a state, and it is the one worth knowing; it goes when it stops being true rather than being replaced by a line that never changes. the timer is a ref and is cleared before each new one. without that, saving twice in quick succession leaves the first timeout running and it fires against the second save — the confirmation vanishing a moment after appearing, which reads as the second save failing. Block moved to its own file and each setting now renders its own. the status belongs to the setting that produced it, and lifting one block's timer into the panel would put it in a component with nothing to do with it. that is also what made the top-right slot possible without absolutely positioning anything. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
|
||||
/**
|
||||
* A message that shows itself and then goes away — "Saved", and whatever joins it.
|
||||
*
|
||||
* ── Why this is not a piece of state somebody sets and clears ──
|
||||
*
|
||||
* The timer is held in a ref and CLEARED before each new one is set. Without that, saving twice in
|
||||
* quick succession leaves the first timeout running, and it fires against the second save — the
|
||||
* confirmation vanishes a moment after appearing, which looks like the second save failed.
|
||||
*
|
||||
* The cleanup on unmount matters for the same reason it always does: this lives in a panel that is
|
||||
* swapped out whenever the nav moves, and a timeout that outlives its component sets state on nothing.
|
||||
*/
|
||||
export const useFlash = (ms = 5000) => {
|
||||
const [showing, setShowing] = useState(false);
|
||||
const timer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
|
||||
const clear = () => {
|
||||
if (timer.current) clearTimeout(timer.current);
|
||||
timer.current = null;
|
||||
};
|
||||
|
||||
const flash = useCallback(() => {
|
||||
clear();
|
||||
setShowing(true);
|
||||
timer.current = setTimeout(() => setShowing(false), ms);
|
||||
}, [ms]);
|
||||
|
||||
useEffect(() => clear, []);
|
||||
|
||||
return [showing, flash] as const;
|
||||
};
|
||||
Reference in New Issue
Block a user