refactor: add ignoreWhenModalOpen parameter to useKeyDown

This commit is contained in:
2026-10-07 14:01:13 +02:00
parent f1ee6922b1
commit 822a66a20f
3 changed files with 40 additions and 28 deletions

View File

@@ -151,12 +151,15 @@ onClick((x, y) => {
} }
}); });
useKeyDown(({ key }) => { useKeyDown(
if (isAnimating.value) return; ({ key }) => {
if (key === "NDS_X") { if (isAnimating.value) return;
handleVisitAll(); if (key === "NDS_X") {
} handleVisitAll();
}); }
},
{ ignoreWhenModalOpen: true },
);
onRender((ctx) => { onRender((ctx) => {
// slash divider // slash divider

View File

@@ -600,27 +600,30 @@ const slide = (rowDir: number, colDir: number) => {
} }
}; };
useKeyDown(({ key }) => { useKeyDown(
if (isAnimating.value || confirmationModal.isOpen) return; ({ key }) => {
switch (key) { if (isAnimating.value) return;
case "NDS_UP": switch (key) {
case "NDS_SWIPE_UP": case "NDS_UP":
slide(-1, 0); case "NDS_SWIPE_UP":
break; slide(-1, 0);
case "NDS_DOWN": break;
case "NDS_SWIPE_DOWN": case "NDS_DOWN":
slide(1, 0); case "NDS_SWIPE_DOWN":
break; slide(1, 0);
case "NDS_LEFT": break;
case "NDS_SWIPE_LEFT": case "NDS_LEFT":
slide(0, -1); case "NDS_SWIPE_LEFT":
break; slide(0, -1);
case "NDS_RIGHT": break;
case "NDS_SWIPE_RIGHT": case "NDS_RIGHT":
slide(0, 1); case "NDS_SWIPE_RIGHT":
break; slide(0, 1);
} break;
}); }
},
{ ignoreWhenModalOpen: true },
);
</script> </script>
<template> <template>

View File

@@ -6,11 +6,17 @@ export type KeyDownCallback = (params: {
repeated: boolean; repeated: boolean;
}) => void; }) => void;
export const useKeyDown = (callback: KeyDownCallback) => { export const useKeyDown = (
callback: KeyDownCallback,
// the confirmation modal's own buttons rely on useKeyDown, so this is opt-in
options: { ignoreWhenModalOpen?: boolean } = {},
) => {
const app = useAppStore(); const app = useAppStore();
const confirmationModal = useConfirmationModal();
const handleKeyDown = (event: KeyboardEvent) => { const handleKeyDown = (event: KeyboardEvent) => {
if (app.lagModalOpen) return; if (app.lagModalOpen) return;
if (options.ignoreWhenModalOpen && confirmationModal.isOpen) return;
const ndsButton = mapCodeToNDS(event.code); const ndsButton = mapCodeToNDS(event.code);
if ( if (