From 6ca3f790845b30c5bcd017dc7c440ba0f0984fa3 Mon Sep 17 00:00:00 2001 From: Innei Date: Fri, 17 Oct 2025 21:43:24 +0800 Subject: [PATCH] fix(ai): add shortcut to open this modal - Integrated new hooks for creating and editing AI shortcuts, improving the user experience for managing shortcuts. - Adjusted layout styles in various components for better visual consistency, including padding and margin updates. - Removed deprecated modal handling for shortcuts, streamlining the codebase. Signed-off-by: Innei --- .../components/layouts/ChatShortcutsRow.tsx | 8 ++- .../modules/ai-task/components/task-item.tsx | 2 +- .../renderer/src/modules/settings/tabs/ai.tsx | 3 +- .../settings/tabs/ai/mcp/MCPServiceItem.tsx | 2 +- .../tabs/ai/mcp/MCPServicesSection.tsx | 41 ++++++------ .../tabs/ai/shortcuts/AIShortcutsSection.tsx | 51 ++------------- .../tabs/ai/shortcuts/ShortcutItem.tsx | 2 +- .../settings/tabs/ai/shortcuts/hooks.tsx | 65 +++++++++++++++++++ 8 files changed, 102 insertions(+), 72 deletions(-) create mode 100644 apps/desktop/layer/renderer/src/modules/settings/tabs/ai/shortcuts/hooks.tsx diff --git a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatShortcutsRow.tsx b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatShortcutsRow.tsx index 286a6cfc3..c1ea5042a 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatShortcutsRow.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-chat/components/layouts/ChatShortcutsRow.tsx @@ -1,10 +1,12 @@ import { AIShortcutButton } from "@follow/components/ui/ai-shortcut-button/index.js" import { DEFAULT_SHORTCUT_TARGETS } from "@follow/shared/settings/interface" +import { nextFrame } from "@follow/utils" import { useCallback, useMemo } from "react" import { useTranslation } from "react-i18next" import { useAISettingValue } from "~/atoms/settings/ai" import { useSettingModal } from "~/modules/settings/modal/use-setting-modal-hack" +import { useCreateAIShortcutModal } from "~/modules/settings/tabs/ai/shortcuts/hooks" import { useMainEntryId } from "../../hooks/useMainEntryId" @@ -40,9 +42,13 @@ export const ChatShortcutsRow: React.FC = ({ onSelect }) return (mainEntryId ? entry : list) ?? [] }, [aiSettings.shortcuts, mainEntryId]) + const handleAddShortcut = useCreateAIShortcutModal() const handleCustomize = useCallback(() => { showSettings("ai") - }, [showSettings]) + nextFrame(() => { + handleAddShortcut() + }) + }, [handleAddShortcut, showSettings]) return (
diff --git a/apps/desktop/layer/renderer/src/modules/ai-task/components/task-item.tsx b/apps/desktop/layer/renderer/src/modules/ai-task/components/task-item.tsx index cb5bb535a..81eac6575 100644 --- a/apps/desktop/layer/renderer/src/modules/ai-task/components/task-item.tsx +++ b/apps/desktop/layer/renderer/src/modules/ai-task/components/task-item.tsx @@ -220,7 +220,7 @@ export const TaskItem = memo(({ task }: { task: AITask }) => { ] return ( -
+
diff --git a/apps/desktop/layer/renderer/src/modules/settings/tabs/ai.tsx b/apps/desktop/layer/renderer/src/modules/settings/tabs/ai.tsx index 5ce84d086..f10c104db 100644 --- a/apps/desktop/layer/renderer/src/modules/settings/tabs/ai.tsx +++ b/apps/desktop/layer/renderer/src/modules/settings/tabs/ai.tsx @@ -1,4 +1,3 @@ -import { Divider } from "@follow/components/ui/divider/Divider.js" import { Label } from "@follow/components/ui/label/index.js" import { useTranslation } from "react-i18next" @@ -57,7 +56,7 @@ export const SettingAI = () => { value: t("integration.title"), }, MCPServicesSection, - , + { type: "title", value: t("tasks.section.title"), diff --git a/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/mcp/MCPServiceItem.tsx b/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/mcp/MCPServiceItem.tsx index bd2b7403f..3302f98ec 100644 --- a/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/mcp/MCPServiceItem.tsx +++ b/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/mcp/MCPServiceItem.tsx @@ -63,7 +63,7 @@ export const MCPServiceItem = ({ ] return ( -
+
diff --git a/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/mcp/MCPServicesSection.tsx b/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/mcp/MCPServicesSection.tsx index 72ad3ba84..a142d6ebc 100644 --- a/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/mcp/MCPServicesSection.tsx +++ b/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/mcp/MCPServicesSection.tsx @@ -362,7 +362,7 @@ export const MCPServicesSection = () => {
{mcpEnabled && ( -
+ <>
)} - {mcpServices.map((service) => ( - - ))} -
+
+ {mcpServices.map((service) => ( + + ))} +
+ )}
) diff --git a/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/shortcuts/AIShortcutsSection.tsx b/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/shortcuts/AIShortcutsSection.tsx index 24756ec5f..520d6b1e9 100644 --- a/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/shortcuts/AIShortcutsSection.tsx +++ b/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/shortcuts/AIShortcutsSection.tsx @@ -4,21 +4,18 @@ import { DEFAULT_SUMMARIZE_TIMELINE_SHORTCUT_ID, defaultAISettings, } from "@follow/shared/settings/defaults" -import type { AIShortcut } from "@follow/shared/settings/interface" import { useEffect } from "react" import { useTranslation } from "react-i18next" import { toast } from "sonner" import { setAISetting, useAISettingValue } from "~/atoms/settings/ai" -import { useModalStack } from "~/components/ui/modal/stacked/hooks" +import { useCreateAIShortcutModal, useEditAIShortcutModal } from "./hooks" import { ShortcutItem } from "./ShortcutItem" -import { ShortcutModalContent } from "./ShortcutModalContent" export const AIShortcutsSection = () => { const { t } = useTranslation("ai") const { shortcuts } = useAISettingValue() - const { present } = useModalStack() useEffect(() => { if (!shortcuts.some((shortcut) => shortcut.id === DEFAULT_SUMMARIZE_TIMELINE_SHORTCUT_ID)) { @@ -34,50 +31,10 @@ export const AIShortcutsSection = () => { setAISetting("shortcuts", [...shortcuts, { ...defaultSummarizeShortcut }]) } - }, [shortcuts, setAISetting]) + }, [shortcuts]) - const handleAddShortcut = () => { - present({ - title: "Add AI Shortcut", - content: ({ dismiss }: { dismiss: () => void }) => ( - { - const newShortcut: AIShortcut = { - ...shortcut, - id: Date.now().toString(), - } - setAISetting("shortcuts", [...shortcuts, newShortcut]) - toast.success(t("shortcuts.added")) - dismiss() - }} - onCancel={dismiss} - /> - ), - }) - } - - const handleEditShortcut = (shortcut: AIShortcut) => { - present({ - title: "Edit AI Shortcut", - content: ({ dismiss }: { dismiss: () => void }) => ( - { - setAISetting( - "shortcuts", - shortcuts.map((s) => - s.id === shortcut.id ? { ...updatedShortcut, id: shortcut.id } : s, - ), - ) - toast.success(t("shortcuts.updated")) - dismiss() - }} - onCancel={dismiss} - /> - ), - }) - } + const handleAddShortcut = useCreateAIShortcutModal() + const handleEditShortcut = useEditAIShortcutModal() const handleDeleteShortcut = (id: string) => { setAISetting( diff --git a/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/shortcuts/ShortcutItem.tsx b/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/shortcuts/ShortcutItem.tsx index 513f87740..bd5923184 100644 --- a/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/shortcuts/ShortcutItem.tsx +++ b/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/shortcuts/ShortcutItem.tsx @@ -38,7 +38,7 @@ export const ShortcutItem = ({ shortcut, onDelete, onToggle, onEdit }: ShortcutI } return ( -
+
diff --git a/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/shortcuts/hooks.tsx b/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/shortcuts/hooks.tsx new file mode 100644 index 000000000..1c557de61 --- /dev/null +++ b/apps/desktop/layer/renderer/src/modules/settings/tabs/ai/shortcuts/hooks.tsx @@ -0,0 +1,65 @@ +import type { AIShortcut } from "@follow/shared/settings/interface" +import { useCallback } from "react" +import { useTranslation } from "react-i18next" +import { toast } from "sonner" + +import { getAISettings, setAISetting } from "~/atoms/settings/ai" +import { useModalStack } from "~/components/ui/modal/stacked/hooks" + +import { ShortcutModalContent } from "./ShortcutModalContent" + +export const useCreateAIShortcutModal = () => { + const { present } = useModalStack() + const { t } = useTranslation("ai") + return useCallback(() => { + present({ + title: "Add AI Shortcut", + content: ({ dismiss }: { dismiss: () => void }) => ( + { + const newShortcut: AIShortcut = { + ...shortcut, + id: Date.now().toString(), + } + const { shortcuts } = getAISettings() + setAISetting("shortcuts", [...shortcuts, newShortcut]) + toast.success(t("shortcuts.added")) + dismiss() + }} + onCancel={dismiss} + /> + ), + }) + }, [present, t]) +} + +export const useEditAIShortcutModal = () => { + const { present } = useModalStack() + const { t } = useTranslation("ai") + return useCallback( + (shortcut: AIShortcut) => { + present({ + title: "Edit AI Shortcut", + content: ({ dismiss }: { dismiss: () => void }) => ( + { + const { shortcuts } = getAISettings() + setAISetting( + "shortcuts", + shortcuts.map((s) => + s.id === shortcut.id ? { ...updatedShortcut, id: shortcut.id } : s, + ), + ) + toast.success(t("shortcuts.updated")) + dismiss() + }} + onCancel={dismiss} + /> + ), + }) + }, + [present, t], + ) +}