fix(watchlist): remove actually removes on the second click
The two-click arm compared against the STATE variable, which each click's handler captured at render time — a quick double-click read the pre-arm value twice, so both clicks merely armed: the bin turned red and nothing was ever deleted. The arm lives in a ref now, compared synchronously, and the window grows to three seconds.
This commit is contained in:
@@ -186,10 +186,23 @@ export function WatchlistTab({ spots, spotStatus, onSpotSelect, onSpotClick }: P
|
|||||||
} catch (e: any) { flash(String(e?.message ?? e), true); }
|
} catch (e: any) { flash(String(e?.message ?? e), true); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Armed through a REF, checked synchronously: the state variable is captured
|
||||||
|
// at render time, so a quick double-click read the pre-arm value twice and
|
||||||
|
// both clicks merely armed — the bin turned red and nothing was ever removed.
|
||||||
|
const removeArmRef = useRef('');
|
||||||
const remove = async (call: string) => {
|
const remove = async (call: string) => {
|
||||||
if (removeArm !== call) { setRemoveArm(call); window.setTimeout(() => setRemoveArm(''), 2500); return; }
|
if (removeArmRef.current !== call) {
|
||||||
|
removeArmRef.current = call;
|
||||||
|
setRemoveArm(call);
|
||||||
|
window.setTimeout(() => {
|
||||||
|
if (removeArmRef.current === call) { removeArmRef.current = ''; setRemoveArm(''); }
|
||||||
|
}, 3000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
removeArmRef.current = '';
|
||||||
|
setRemoveArm('');
|
||||||
try { await WatchlistRemove(call); await refresh(); }
|
try { await WatchlistRemove(call); await refresh(); }
|
||||||
catch (e: any) { setError(String(e?.message ?? e)); }
|
catch (e: any) { flash(String(e?.message ?? e), true); }
|
||||||
};
|
};
|
||||||
|
|
||||||
const isOnAir = (e: WLEntry): boolean =>
|
const isOnAir = (e: WLEntry): boolean =>
|
||||||
|
|||||||
Reference in New Issue
Block a user