From 2a2085a0f17536fe119afcde7c87fe963c65e8f2 Mon Sep 17 00:00:00 2001 From: Innei Date: Mon, 8 Sep 2025 22:03:05 +0800 Subject: [PATCH] feat: add AI shortcut functionality for enhanced user interaction - Introduced a new hook, useAIShortcut, to manage keyboard shortcuts for creating new chats and closing the AI chat panel. - Integrated the useAIShortcut hook into the AIChatRoot component to enable these shortcuts when the AI chat is focused. These changes improve user experience by providing quick access to essential chat functions through keyboard shortcuts. Signed-off-by: Innei --- .../ai-chat/components/layouts/AIChatRoot.tsx | 3 +- .../modules/ai-chat/hooks/useAIShortcut.ts | 29 +++++++++++++++++++ .../modules/entry-column/Items/all-item.tsx | 18 +++++------- 3 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 apps/desktop/layer/renderer/src/modules/ai-chat/hooks/useAIShortcut.ts diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/AIChatRoot.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/AIChatRoot.tsx index 7a8a55b84..dc9ece230 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/AIChatRoot.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/AIChatRoot.tsx @@ -5,6 +5,7 @@ import { useEffect, useMemo, useRef } from "react" import { Focusable } from "~/components/common/Focusable" import { HotkeyScope } from "~/constants" +import { useAIShortcut } from "../../hooks/useAIShortcut" import type { AIPanelRefs } from "../../store/AIChatContext" import { AIChatStoreContext, @@ -34,7 +35,7 @@ const AIChatRootInner: FC = ({ children, chatId: externalChatId const panelRef = useRef(null!) const inputRef = useRef(null!) const refsContext = useMemo(() => ({ panelRef, inputRef }), [panelRef, inputRef]) - + useAIShortcut() if (!currentChatId) { return (
diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/hooks/useAIShortcut.ts b/apps/desktop/layer/renderer/src/modules/ai-chat/hooks/useAIShortcut.ts new file mode 100644 index 000000000..ba410de1e --- /dev/null +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/hooks/useAIShortcut.ts @@ -0,0 +1,29 @@ +import { useGlobalFocusableScopeSelector } from "@follow/components/common/Focusable/hooks.js" +import { useEffect } from "react" +import { tinykeys } from "tinykeys" + +import { setAIPanelVisibility } from "~/atoms/settings/ai" +import { FocusablePresets } from "~/components/common/Focusable" + +import { useChatActions } from "../store/hooks" + +export const useAIShortcut = () => { + const isFocus = useGlobalFocusableScopeSelector(FocusablePresets.isAIChat) + + const chatActions = useChatActions() + useEffect(() => { + if (!isFocus) return + return tinykeys(document.documentElement, { + "$mod+n": (e) => { + e.preventDefault() + // New chat + chatActions.newChat() + }, + "$mod+w": (e) => { + e.preventDefault() + // close AI chat + setAIPanelVisibility(false) + }, + }) + }, [chatActions, isFocus]) +} diff --git a/apps/desktop/layer/renderer/src/modules/entry-column/Items/all-item.tsx b/apps/desktop/layer/renderer/src/modules/entry-column/Items/all-item.tsx index 4d21bb6a5..de308c1db 100644 --- a/apps/desktop/layer/renderer/src/modules/entry-column/Items/all-item.tsx +++ b/apps/desktop/layer/renderer/src/modules/entry-column/Items/all-item.tsx @@ -442,8 +442,8 @@ export const AllItem: EntryListItemFC = ({ entryId, entryPreview, translation }) )}
-
-
+
+
-
- - {dayjs - .duration(dayjs(entry.publishedAt).diff(dayjs(), "minute"), "minute") - .humanize()} - {t("space")} - {t("words.ago")} - -
+ + {dayjs.duration(dayjs(entry.publishedAt).diff(dayjs(), "minute"), "minute").humanize()} + {t("space")} + {t("words.ago")} +