Auto-navigate SpoolBuddy to dashboard on tag scan

When an NFC tag is first detected while the UI is on a non-dashboard
  page, automatically navigate to the main dashboard. Uses edge detection
  (previous ref) so a persistently present tag doesn't block navigation
  to other pages. Also wakes the screen if the display was blanked.
This commit is contained in:
maziggy
2026-03-26 10:40:40 +01:00
parent 1c35ed94a5
commit 57a774c32f
3 changed files with 63 additions and 61 deletions
@@ -100,15 +100,17 @@ export function SpoolBuddyLayout() {
};
}, [resetActivity]);
// Auto-navigate to dashboard when a tag is detected on a non-dashboard page
// Auto-navigate to dashboard when a NEW tag is detected (transition from no-tag to tag)
const tagDetected = Boolean(sbState.matchedSpool || sbState.unknownTagUid);
const prevTagDetected = useRef(false);
useEffect(() => {
if (tagDetected) {
if (tagDetected && !prevTagDetected.current) {
resetActivity();
if (location.pathname !== '/spoolbuddy') {
navigate('/spoolbuddy');
}
}
prevTagDetected.current = tagDetected;
}, [tagDetected, location.pathname, navigate, resetActivity]);
// Screen blank timer