Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
refactor(inbox): share the single-key shortcut guard in one hook (MUL-9831) (#11176)
Jiayuan Zhang370b2643f6fa
diff --git a/packages/views/inbox/components/inbox-empty-state.tsx b/packages/views/inbox/components/inbox-empty-state.tsxindex 04d90a807e..85b48d6113 100644--- a/packages/views/inbox/components/inbox-empty-state.tsx+++ b/packages/views/inbox/components/inbox-empty-state.tsx@@ -1,6 +1,6 @@"use client";-import { useEffect, useMemo, useRef, useState } from "react";+import { useMemo, useState } from "react";import { useQuery, useQueryClient } from "@tanstack/react-query";import { toast } from "sonner";import {@@ -28,22 +28,14 @@ import {type LastInboxCleared,} from "@multica/core/inbox/selection-store";import { openCreateIssueWithPreference } from "@multica/core/issues/stores";-import { useModalStore } from "@multica/core/modals";import { useIsGuest } from "@multica/core/permissions";-import {- getShortcut,- isEditableShortcutTarget,- isPortalLayerShortcutTarget,- shortcutMatchesEvent,-} from "@multica/core/shortcuts";import type { SnoozedInboxIssue, WorkspaceWorkingAgent } from "@multica/core/types";-import { isImeComposing } from "@multica/core/utils";import { ActionShortcutKeycaps } from "../../common/shortcut-keycaps";import { useLocale, useT } from "../../i18n";import { useBuiltinViewNavigation } from "../../issue-views/builtin-views";import { useNavigation } from "../../navigation";import { formatSnoozeTime } from "./inbox-snooze-time";-import { hasInboxUndo } from "./inbox-undo-toast";+import { useInboxUndoShortcut } from "./use-inbox-shortcut";import { useRestoreInbox } from "./use-leave-inbox-row";const NO_SNOOZED: SnoozedInboxIssue[] = [];@@ -190,27 +182,7 @@ export function InboxEmptyState({// Z undoes what the inline undo shows, once its toast is gone.const showsUndo = !isArchivedView && visibleCount === 0 && !!lastCleared && canUndoCleared(lastCleared);- const undoShortcutRef = useRef<(() => void) | null>(null);- useEffect(() => {- undoShortcutRef.current = showsUndo && lastCleared ? () => void handleUndoCleared(lastCleared) : null;- });- useEffect(() => {- const onKeyDown = (event: KeyboardEvent) => {- // A showing undo toast is the latest action, and the shortcut is its.- if (hasInboxUndo()) return;- if (event.defaultPrevented || event.repeat || isImeComposing(event)) return;- if (isEditableShortcutTarget(event.target)) return;- if (isPortalLayerShortcutTarget(event.target)) return;- if (useModalStore.getState().modal) return;- if (!shortcutMatchesEvent(getShortcut("undoInboxAction"), event)) return;- const undo = undoShortcutRef.current;- if (!undo) return;- event.preventDefault();- undo();- };- document.addEventListener("keydown", onKeyDown);- return () => document.removeEventListener("keydown", onKeyDown);- }, []);+ useInboxUndoShortcut(showsUndo && lastCleared ? () => void handleUndoCleared(lastCleared) : null);const undoKeycaps = !isCompact && <ActionShortcutKeycaps action="undoInboxAction" />;// Desktop prompt when active notifications exist in the Work panel.diff --git a/packages/views/inbox/components/inbox-kept-actions.tsx b/packages/views/inbox/components/inbox-kept-actions.tsxindex c53bb8933d..46c63716d0 100644--- a/packages/views/inbox/components/inbox-kept-actions.tsx+++ b/packages/views/inbox/components/inbox-kept-actions.tsx@@ -1,20 +1,12 @@"use client";-import { type ReactNode, useEffect, useRef } from "react";+import type { ReactNode } from "react";import { Archive, ArrowDown, ArrowRight, CheckCircle2, Undo2 } from "@multica/ui/icons";import { Button } from "@multica/ui/components/ui/button";import { TooltipHint } from "@multica/ui/components/common/tooltip-hint";import { useIssueStatuses } from "@multica/core/issue-statuses/hooks";import type { InboxBarAction } from "@multica/core/inbox/auto-archive";import type { KeptInboxRow } from "@multica/core/inbox/open-row";-import { useModalStore } from "@multica/core/modals";-import {- getShortcut,- isEditableShortcutTarget,- isPortalLayerShortcutTarget,- shortcutMatchesEvent,-} from "@multica/core/shortcuts";-import { isImeComposing } from "@multica/core/utils";import { useActorName } from "@multica/core/workspace/hooks";import type { InboxItem } from "@multica/core/types";import { useLocale, useT } from "../../i18n";@@ -23,7 +15,7 @@ import { useStatusLabel } from "../../issues/utils/status-label";import { formatSnoozeTime } from "./inbox-snooze-time";import { getInboxDisplayTitle, isAutopilotQuotaNotice } from "./inbox-display";import { InboxBar, InboxBarSeparator, InboxBarStatus } from "./inbox-bar";-import { hasInboxUndo } from "./inbox-undo-toast";+import { useInboxUndoShortcut } from "./use-inbox-shortcut";/*** How a kept row (`keepOpenInboxRow`) says why it is settled: `line` in its@@ -108,27 +100,7 @@ export function InboxKeptActions({onGoToMyWork?: () => void;}) {const { t } = useT("inbox");- const undoRef = useRef(onUndo);- useEffect(() => {- undoRef.current = onUndo;- });- useEffect(() => {- const onKeyDown = (event: KeyboardEvent) => {- // A showing undo toast is the latest action, and the shortcut is its.- if (hasInboxUndo()) return;- if (event.defaultPrevented || event.repeat || isImeComposing(event)) return;- if (isEditableShortcutTarget(event.target)) return;- if (isPortalLayerShortcutTarget(event.target)) return;- if (useModalStore.getState().modal) return;- if (!shortcutMatchesEvent(getShortcut("undoInboxAction"), event)) return;- const undo = undoRef.current;- if (!undo) return;- event.preventDefault();- undo();- };- document.addEventListener("keydown", onKeyDown);- return () => document.removeEventListener("keydown", onKeyDown);- }, []);+ useInboxUndoShortcut(onUndo ?? null);const statusIcon =icon ?? (inboxCleared ? <CheckCircle2 className="text-success" /> : <Archive />);const statusLabel = inboxCleared ? (diff --git a/packages/views/inbox/components/inbox-page.tsx b/packages/views/inbox/components/inbox-page.tsxindex 4bdc1436d8..043e239969 100644--- a/packages/views/inbox/components/inbox-page.tsx+++ b/packages/views/inbox/components/inbox-page.tsx@@ -14,13 +14,6 @@ import { useWorkspaceId } from "@multica/core/hooks";import { ApiError, errorCode } from "@multica/core/api";import { useWorkspacePaths } from "@multica/core/paths";import { useModalStore } from "@multica/core/modals";-import {- getShortcut,- isEditableShortcutTarget,- isPortalLayerShortcutTarget,- shortcutMatchesEvent,-} from "@multica/core/shortcuts";-import { isImeComposing } from "@multica/core/utils";import { useIssueDraftStore } from "@multica/core/issues/stores/draft-store";import { cachedIssueRouteRef } from "@multica/core/issues/canonical-id";import { useInboxSelectionStore, type LastInboxCleared } from "@multica/core/inbox/selection-store";@@ -133,6 +126,7 @@ import {useRestoreInbox,} from "./use-leave-inbox-row";import { useInboxSnooze } from "./use-inbox-snooze";+import { useInboxShortcut } from "./use-inbox-shortcut";import { InboxAppRequest } from "../../common/app-requests";import { useT } from "../../i18n";import { useLimitRecoveryPrompt } from "../../modals/use-limit-recovery-prompt";@@ -706,29 +700,10 @@ export function InboxPage() {unsubscribeArchive({ id, issueId: item.issue_id }, scope);};- // Keep the listener stable while using the latest selected-item action.- const actionOnSelectedRef = useRef<(() => void) | null>(null);- useEffect(() => {- actionOnSelectedRef.current = selected- ? () => (isArchivedView ? handleUnarchive(selected.id) : handleArchive(selected.id))- : null;- });-- useEffect(() => {- const onKeyDown = (event: KeyboardEvent) => {- if (event.defaultPrevented || event.repeat || isImeComposing(event)) return;- if (isEditableShortcutTarget(event.target)) return;- if (isPortalLayerShortcutTarget(event.target)) return;- if (useModalStore.getState().modal) return;- if (!shortcutMatchesEvent(getShortcut("archiveInboxItem"), event)) return;- const run = actionOnSelectedRef.current;- if (!run) return;- event.preventDefault();- run();- };- document.addEventListener("keydown", onKeyDown);- return () => document.removeEventListener("keydown", onKeyDown);- }, []);+ useInboxShortcut(+ "archiveInboxItem",+ selected ? () => (isArchivedView ? handleUnarchive(selected.id) : handleArchive(selected.id)) : null,+ );// Batch operationsconst handleMarkAllRead = () => {diff --git a/packages/views/inbox/components/inbox-shortcut.ts b/packages/views/inbox/components/inbox-shortcut.tsnew file mode 100644index 0000000000..ebe0ffab6f--- /dev/null+++ b/packages/views/inbox/components/inbox-shortcut.ts@@ -0,0 +1,22 @@+import { useModalStore } from "@multica/core/modals";+import {+ getShortcut,+ isEditableShortcutTarget,+ isPortalLayerShortcutTarget,+ shortcutMatchesEvent,+ type ShortcutActionId,+} from "@multica/core/shortcuts";+import { isImeComposing } from "@multica/core/utils";++/**+ * Whether a keydown is `action`'s single-key Inbox shortcut and the Inbox's to+ * take: not handled already, not a held key or an IME composition, not typed+ * into a field, and no menu, dialog or modal on top.+ */+export function isInboxShortcut(event: KeyboardEvent, action: ShortcutActionId): boolean {+ if (event.defaultPrevented || event.repeat || isImeComposing(event)) return false;+ if (isEditableShortcutTarget(event.target)) return false;+ if (isPortalLayerShortcutTarget(event.target)) return false;+ if (useModalStore.getState().modal) return false;+ return shortcutMatchesEvent(getShortcut(action), event);+}diff --git a/packages/views/inbox/components/inbox-undo-toast.ts b/packages/views/inbox/components/inbox-undo-toast.tsindex 315be4756c..2a97dedab8 100644--- a/packages/views/inbox/components/inbox-undo-toast.ts+++ b/packages/views/inbox/components/inbox-undo-toast.ts@@ -1,12 +1,5 @@import { toast } from "sonner";-import { useModalStore } from "@multica/core/modals";-import {- getShortcut,- isEditableShortcutTarget,- isPortalLayerShortcutTarget,- shortcutMatchesEvent,-} from "@multica/core/shortcuts";-import { isImeComposing } from "@multica/core/utils";+import { isInboxShortcut } from "./inbox-shortcut";/** Long enough to read the toast and reach for its undo. */export const INBOX_UNDO_TOAST_DURATION = 10_000;@@ -20,11 +13,7 @@ const clear = (id: string | number) => {};function onKeyDown(event: KeyboardEvent) {- if (event.defaultPrevented || event.repeat || isImeComposing(event)) return;- if (isEditableShortcutTarget(event.target)) return;- if (isPortalLayerShortcutTarget(event.target)) return;- if (useModalStore.getState().modal) return;- if (!shortcutMatchesEvent(getShortcut("undoInboxAction"), event)) return;+ if (!isInboxShortcut(event, "undoInboxAction")) return;const undo = takeInboxUndo();if (!undo) return;event.preventDefault();diff --git a/packages/views/inbox/components/unsubscribe-archive-button.tsx b/packages/views/inbox/components/unsubscribe-archive-button.tsxindex 320bb505d3..99ae52764a 100644--- a/packages/views/inbox/components/unsubscribe-archive-button.tsx+++ b/packages/views/inbox/components/unsubscribe-archive-button.tsx@@ -1,6 +1,6 @@"use client";-import { useEffect, useRef, useState } from "react";+import { useState } from "react";import { useQuery } from "@tanstack/react-query";import { BellOff, ListTree } from "@multica/ui/icons";import { IconButton } from "@multica/ui/components/common/icon-button";@@ -13,20 +13,13 @@ import {DropdownMenuTrigger,} from "@multica/ui/components/ui/dropdown-menu";import { useWorkspaceId } from "@multica/core/hooks";-import { useModalStore } from "@multica/core/modals";import type { InboxUnsubscribeScope } from "@multica/core/inbox/mutations";import { childIssuesOptions, issueDetailOptions, issueSubscribersOptions } from "@multica/core/issues/queries";import { isOwnIssue } from "@multica/core/issues/ownership";import { agentListOptions } from "@multica/core/workspace/queries";-import {- getShortcut,- isEditableShortcutTarget,- isPortalLayerShortcutTarget,- shortcutMatchesEvent,-} from "@multica/core/shortcuts";-import { isImeComposing } from "@multica/core/utils";import { ActionShortcutKeycaps } from "../../common/shortcut-keycaps";import { useT } from "../../i18n";+import { useInboxShortcut } from "./use-inbox-shortcut";/*** "Unsubscribe & archive" in the Inbox bar of an issue opened from the Inbox.@@ -67,25 +60,10 @@ export function UnsubscribeArchiveButton({const childCountKnown = childrenLoaded && !childrenFetching;const asksScope = !childCountKnown || children.length > 0;- const shortcutRef = useRef<(() => void) | null>(null);- useEffect(() => {- shortcutRef.current = offered ? (asksScope ? () => setMenuOpen(true) : () => onConfirm("issue")) : null;- });- useEffect(() => {- const onKeyDown = (event: KeyboardEvent) => {- if (event.defaultPrevented || event.repeat || isImeComposing(event)) return;- if (isEditableShortcutTarget(event.target)) return;- if (isPortalLayerShortcutTarget(event.target)) return;- if (useModalStore.getState().modal) return;- if (!shortcutMatchesEvent(getShortcut("unsubscribeArchiveInboxItem"), event)) return;- const run = shortcutRef.current;- if (!run) return;- event.preventDefault();- run();- };- document.addEventListener("keydown", onKeyDown);- return () => document.removeEventListener("keydown", onKeyDown);- }, []);+ useInboxShortcut(+ "unsubscribeArchiveInboxItem",+ offered ? (asksScope ? () => setMenuOpen(true) : () => onConfirm("issue")) : null,+ );if (!offered) return null;diff --git a/packages/views/inbox/components/use-inbox-shortcut.test.tsx b/packages/views/inbox/components/use-inbox-shortcut.test.tsxnew file mode 100644index 0000000000..bc97b3264f--- /dev/null+++ b/packages/views/inbox/components/use-inbox-shortcut.test.tsx@@ -0,0 +1,168 @@+import { afterEach, describe, expect, it, vi } from "vitest";+import { fireEvent, renderHook } from "@testing-library/react";+import { toast } from "sonner";+import { useModalStore } from "@multica/core/modals";+import { hasInboxUndo, toastInboxUndo } from "./inbox-undo-toast";+import { useInboxShortcut, useInboxUndoShortcut } from "./use-inbox-shortcut";++vi.mock("sonner", () => {+ let next = 0;+ return { toast: { success: vi.fn(() => ++next), dismiss: vi.fn() } };+});++const E = { key: "e", code: "KeyE" };+const Z = { key: "z", code: "KeyZ" };+const press = (init: KeyboardEventInit, target: Element = document.body) => fireEvent.keyDown(target, init);++function mountTarget(html: string) {+ const host = document.createElement("div");+ host.innerHTML = html;+ document.body.appendChild(host);+ return host;+}++afterEach(() => {+ useModalStore.getState().close();+ document.body.innerHTML = "";+ if (hasInboxUndo()) {+ const options = vi.mocked(toast.success).mock.calls.at(-1)![1] as unknown as { onAutoClose: () => void };+ options.onAutoClose();+ }+ vi.clearAllMocks();+});++describe("useInboxShortcut", () => {+ it("runs the handler on its shortcut and takes the key", () => {+ const handler = vi.fn();+ renderHook(() => useInboxShortcut("archiveInboxItem", handler));+ expect(press(E)).toBe(false);+ expect(handler).toHaveBeenCalledTimes(1);+ });++ it("ignores other keys", () => {+ const handler = vi.fn();+ renderHook(() => useInboxShortcut("archiveInboxItem", handler));+ expect(press({ key: "h", code: "KeyH" })).toBe(true);+ expect(press({ ...E, shiftKey: true })).toBe(true);+ expect(handler).not.toHaveBeenCalled();+ });++ it("leaves the key alone without a handler", () => {+ renderHook(() => useInboxShortcut("archiveInboxItem", null));+ expect(press(E)).toBe(true);+ });++ it("runs the latest handler", () => {+ const first = vi.fn();+ const second = vi.fn();+ const { rerender } = renderHook(({ handler }) => useInboxShortcut("archiveInboxItem", handler), {+ initialProps: { handler: first as (() => void) | null },+ });+ rerender({ handler: second });+ press(E);+ expect(first).not.toHaveBeenCalled();+ expect(second).toHaveBeenCalledTimes(1);+ rerender({ handler: null });+ expect(press(E)).toBe(true);+ expect(second).toHaveBeenCalledTimes(1);+ });++ it("stops listening once unmounted", () => {+ const handler = vi.fn();+ const { unmount } = renderHook(() => useInboxShortcut("archiveInboxItem", handler));+ unmount();+ press(E);+ expect(handler).not.toHaveBeenCalled();+ });++ it("ignores a held key", () => {+ const handler = vi.fn();+ renderHook(() => useInboxShortcut("archiveInboxItem", handler));+ expect(press({ ...E, repeat: true })).toBe(true);+ expect(handler).not.toHaveBeenCalled();+ });++ it("ignores IME composition", () => {+ const handler = vi.fn();+ renderHook(() => useInboxShortcut("archiveInboxItem", handler));+ expect(press({ ...E, isComposing: true })).toBe(true);+ expect(press({ ...E, keyCode: 229 })).toBe(true);+ expect(handler).not.toHaveBeenCalled();+ });++ it("ignores a key another listener already handled", () => {+ const handler = vi.fn();+ renderHook(() => useInboxShortcut("archiveInboxItem", handler));+ const host = mountTarget("<button>x</button>");+ host.addEventListener("keydown", (event) => event.preventDefault());+ press(E, host.querySelector("button")!);+ expect(handler).not.toHaveBeenCalled();+ });++ it.each([+ ["an input", "<input />", "input"],+ ["a textarea", "<textarea></textarea>", "textarea"],+ ["a select", "<select></select>", "select"],+ ["rich text", "<div contenteditable='true'><p>x</p></div>", "p"],+ ])("ignores typing into %s", (_name, html, selector) => {+ const handler = vi.fn();+ renderHook(() => useInboxShortcut("archiveInboxItem", handler));+ const host = mountTarget(html);+ expect(press(E, host.querySelector(selector)!)).toBe(true);+ expect(handler).not.toHaveBeenCalled();+ });++ it.each(["menu", "dialog", "alertdialog", "listbox"])("ignores keys inside an open %s", (role) => {+ const handler = vi.fn();+ renderHook(() => useInboxShortcut("archiveInboxItem", handler));+ const host = mountTarget(`<div role="${role}"><button>x</button></div>`);+ expect(press(E, host.querySelector("button")!)).toBe(true);+ expect(handler).not.toHaveBeenCalled();+ });++ it("ignores keys while a modal layer makes the page inert", () => {+ const handler = vi.fn();+ renderHook(() => useInboxShortcut("archiveInboxItem", handler));+ mountTarget("<div data-base-ui-inert></div>");+ expect(press(E)).toBe(true);+ expect(handler).not.toHaveBeenCalled();+ });++ it("ignores keys while a modal is open", () => {+ const handler = vi.fn();+ renderHook(() => useInboxShortcut("archiveInboxItem", handler));+ useModalStore.getState().open("create-issue");+ expect(press(E)).toBe(true);+ expect(handler).not.toHaveBeenCalled();+ });+});++describe("useInboxUndoShortcut", () => {+ it("undoes on Z", () => {+ const undo = vi.fn();+ renderHook(() => useInboxUndoShortcut(undo));+ expect(press(Z)).toBe(false);+ expect(undo).toHaveBeenCalledTimes(1);+ });++ it("leaves Z to a showing undo toast, then takes it back", () => {+ const undo = vi.fn();+ const toastUndo = vi.fn();+ renderHook(() => useInboxUndoShortcut(undo));+ toastInboxUndo("Notification archived", { label: "Undo", undo: toastUndo });++ press(Z);+ expect(toastUndo).toHaveBeenCalledTimes(1);+ expect(undo).not.toHaveBeenCalled();+ expect(hasInboxUndo()).toBe(false);++ press(Z);+ expect(undo).toHaveBeenCalledTimes(1);+ expect(toastUndo).toHaveBeenCalledTimes(1);+ });++ it("leaves Z alone without an undo", () => {+ renderHook(() => useInboxUndoShortcut(null));+ expect(press(Z)).toBe(true);+ });+});diff --git a/packages/views/inbox/components/use-inbox-shortcut.ts b/packages/views/inbox/components/use-inbox-shortcut.tsnew file mode 100644index 0000000000..059e07bd14--- /dev/null+++ b/packages/views/inbox/components/use-inbox-shortcut.ts@@ -0,0 +1,48 @@+"use client";++import { useEffect, useRef } from "react";+import type { ShortcutActionId } from "@multica/core/shortcuts";+import { isInboxShortcut } from "./inbox-shortcut";+import { hasInboxUndo } from "./inbox-undo-toast";++const neverYields = () => false;++function useDocumentInboxShortcut(+ action: ShortcutActionId,+ handler: (() => void) | null,+ yields: () => boolean,+) {+ const handlerRef = useRef(handler);+ useEffect(() => {+ handlerRef.current = handler;+ });+ useEffect(() => {+ const onKeyDown = (event: KeyboardEvent) => {+ // Yielding leaves the event untouched, so a later listener can take it.+ if (yields()) return;+ if (!isInboxShortcut(event, action)) return;+ const run = handlerRef.current;+ if (!run) return;+ event.preventDefault();+ run();+ };+ document.addEventListener("keydown", onKeyDown);+ return () => document.removeEventListener("keydown", onKeyDown);+ }, [action, yields]);+}++/**+ * Runs `handler` on `action`'s Inbox shortcut while mounted; `null` leaves the+ * key alone. The latest `handler` answers, without re-subscribing.+ */+export function useInboxShortcut(action: ShortcutActionId, handler: (() => void) | null) {+ useDocumentInboxShortcut(action, handler, neverYields);+}++/**+ * Runs `undo` on the undo shortcut (Z), except while an undo toast shows: the+ * toast is the latest action, and the shortcut is its.+ */+export function useInboxUndoShortcut(undo: (() => void) | null) {+ useDocumentInboxShortcut("undoInboxAction", undo, hasInboxUndo);+}diff --git a/packages/views/issues/actions/issue-inbox-actions.tsx b/packages/views/issues/actions/issue-inbox-actions.tsxindex 5a178a0dd6..85f727d5e2 100644--- a/packages/views/issues/actions/issue-inbox-actions.tsx+++ b/packages/views/issues/actions/issue-inbox-actions.tsx@@ -1,11 +1,10 @@"use client";-import { useMemo, type ReactNode, useEffect, useRef, useState } from "react";+import { useMemo, type ReactNode, useState } from "react";import { useQuery } from "@tanstack/react-query";import { AlarmClock, ChevronDown } from "@multica/ui/icons";import { Button } from "@multica/ui/components/ui/button";import { useWorkspaceId } from "@multica/core/hooks";-import { useModalStore } from "@multica/core/modals";import type { InboxUnsubscribeScope } from "@multica/core/inbox/mutations";import type { LastInboxCleared } from "@multica/core/inbox/selection-store";import type { InboxItem } from "@multica/core/types";@@ -13,18 +12,12 @@ import { findSnoozedInboxIssue, snoozedInboxOptions } from "@multica/core/inbox/import { nextInboxRow } from "@multica/core/inbox/open-row";import { useWorkspacePaths } from "@multica/core/paths";import { useIsGuest } from "@multica/core/permissions";-import {- getShortcut,- isEditableShortcutTarget,- isPortalLayerShortcutTarget,- shortcutMatchesEvent,-} from "@multica/core/shortcuts";-import { isImeComposing } from "@multica/core/utils";import { InboxArchiveButton, InboxBar, InboxBarButton, InboxBarStatus, InboxOpenBar } from "../../inbox/components/inbox-bar";import { inboxRowHref } from "../../inbox/components/inbox-display";import { InboxKeptActions, InboxNextButton, useKeptInboxRowText } from "../../inbox/components/inbox-kept-actions";import { InboxSnoozeMenu } from "../../inbox/components/inbox-snooze-menu";import { formatSnoozeTime } from "../../inbox/components/inbox-snooze-time";+import { useInboxShortcut } from "../../inbox/components/use-inbox-shortcut";import { useInboxSnooze } from "../../inbox/components/use-inbox-snooze";import { useFilteredInboxRows } from "../../inbox/components/use-filtered-inbox-rows";import { useSidebarInboxIssue } from "../../inbox/components/use-sidebar-inbox-issue";@@ -154,35 +147,12 @@ export function IssueInboxBar({ issueId, issueActions }: { issueId: string; issu};const cause = useMoveOnAfterAutoArchive({ settled, next, onNext: moveOn });- const archiveRef = useRef<(() => void) | null>(null);- const snoozeRef = useRef<(() => void) | null>(null);- useEffect(() => {- // Archived already, E moves on (to the next notification or Inbox Zero).- archiveRef.current = item ? archiveItem : settled ? moveOn : null;- snoozeRef.current = item- ? () => setSnoozeOpen(true)- : snoozed- ? () => unsnooze(snoozed.item_id, issueId)- : null;- });- useEffect(() => {- const onKeyDown = (event: KeyboardEvent) => {- if (event.defaultPrevented || event.repeat || isImeComposing(event)) return;- if (isEditableShortcutTarget(event.target)) return;- if (isPortalLayerShortcutTarget(event.target)) return;- if (useModalStore.getState().modal) return;- const run = shortcutMatchesEvent(getShortcut("archiveInboxItem"), event)- ? archiveRef.current- : shortcutMatchesEvent(getShortcut("snoozeInboxItem"), event)- ? snoozeRef.current- : null;- if (!run) return;- event.preventDefault();- run();- };- document.addEventListener("keydown", onKeyDown);- return () => document.removeEventListener("keydown", onKeyDown);- }, []);+ // Archived already, E moves on (to the next notification or Inbox Zero).+ useInboxShortcut("archiveInboxItem", item ? archiveItem : settled ? moveOn : null);+ useInboxShortcut(+ "snoozeInboxItem",+ item ? () => setSnoozeOpen(true) : snoozed ? () => unsnooze(snoozed.item_id, issueId) : null,+ );if (!item) {if (snoozed) {