From 27eef50b9f2f0a56aa723f4edaefdd235578571c Mon Sep 17 00:00:00 2001 From: Jason Young <44939412+farion1231@users.noreply.github.com> Date: Thu, 21 Aug 2025 00:49:42 +0800 Subject: [PATCH] fix: sidebar code icon reset bug (#9307) (#9333) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 修复侧边栏重置时 Code 图标消失的问题 (#9307) 问题原因: - types/index.ts 中的 SidebarIcon 类型定义缺少 'code_tools' - 存在重复的类型定义和常量定义导致不一致 修复内容: - 在 types/index.ts 的 SidebarIcon 类型中添加 'code_tools' - 删除 minapps.ts 中重复的 DEFAULT_SIDEBAR_ICONS 常量 - 统一从 @renderer/types 导入 SidebarIcon 类型 - 删除 settings.ts 中重复的 SidebarIcon 类型定义 这确保了在导航栏设置为左侧时,点击侧边栏设置的重置按钮后, Code 图标能够正确显示。 * refactor: 将侧边栏配置移至 config 目录 根据 code review 建议,将侧边栏相关配置从 store/settings.ts 移动到 config/sidebar.ts,使配置管理更加清晰。 改动内容: - 创建 config/sidebar.ts 存放侧边栏配置常量 - 更新相关文件的导入路径 - 在 settings.ts 中重新导出以保持向后兼容 - 添加 REQUIRED_SIDEBAR_ICONS 常量便于未来扩展 这个改动保持了最小化原则,不影响现有功能。 --- src/renderer/src/config/sidebar.ts | 23 ++++++++++++++++++ .../DisplaySettings/DisplaySettings.tsx | 2 +- .../DisplaySettings/SidebarIconsManager.tsx | 3 +-- src/renderer/src/store/migrate.ts | 3 ++- src/renderer/src/store/minapps.ts | 12 +--------- src/renderer/src/store/settings.ts | 24 ++++--------------- src/renderer/src/types/index.ts | 2 +- 7 files changed, 33 insertions(+), 36 deletions(-) create mode 100644 src/renderer/src/config/sidebar.ts diff --git a/src/renderer/src/config/sidebar.ts b/src/renderer/src/config/sidebar.ts new file mode 100644 index 0000000000..90a83cf42d --- /dev/null +++ b/src/renderer/src/config/sidebar.ts @@ -0,0 +1,23 @@ +import { SidebarIcon } from '@renderer/types' + +/** + * 默认显示的侧边栏图标 + * 这些图标会在侧边栏中默认显示 + */ +export const DEFAULT_SIDEBAR_ICONS: SidebarIcon[] = [ + 'assistants', + 'agents', + 'paintings', + 'translate', + 'minapp', + 'knowledge', + 'files', + 'code_tools' +] + +/** + * 必须显示的侧边栏图标(不能被隐藏) + * 这些图标必须始终在侧边栏中可见 + * 抽取为参数方便未来扩展 + */ +export const REQUIRED_SIDEBAR_ICONS: SidebarIcon[] = ['assistants'] diff --git a/src/renderer/src/pages/settings/DisplaySettings/DisplaySettings.tsx b/src/renderer/src/pages/settings/DisplaySettings/DisplaySettings.tsx index acc1f668e2..1c4749aebd 100644 --- a/src/renderer/src/pages/settings/DisplaySettings/DisplaySettings.tsx +++ b/src/renderer/src/pages/settings/DisplaySettings/DisplaySettings.tsx @@ -3,13 +3,13 @@ import { ResetIcon } from '@renderer/components/Icons' import { HStack } from '@renderer/components/Layout' import TextBadge from '@renderer/components/TextBadge' import { isMac, THEME_COLOR_PRESETS } from '@renderer/config/constant' +import { DEFAULT_SIDEBAR_ICONS } from '@renderer/config/sidebar' import { useTheme } from '@renderer/context/ThemeProvider' import { useNavbarPosition, useSettings } from '@renderer/hooks/useSettings' import useUserTheme from '@renderer/hooks/useUserTheme' import { useAppDispatch } from '@renderer/store' import { AssistantIconType, - DEFAULT_SIDEBAR_ICONS, setAssistantIconType, setClickAssistantToShowTopic, setCustomCss, diff --git a/src/renderer/src/pages/settings/DisplaySettings/SidebarIconsManager.tsx b/src/renderer/src/pages/settings/DisplaySettings/SidebarIconsManager.tsx index d5ff9cd69b..8e4f609b53 100644 --- a/src/renderer/src/pages/settings/DisplaySettings/SidebarIconsManager.tsx +++ b/src/renderer/src/pages/settings/DisplaySettings/SidebarIconsManager.tsx @@ -10,14 +10,13 @@ import { import { getSidebarIconLabel } from '@renderer/i18n/label' import { useAppDispatch } from '@renderer/store' import { setSidebarIcons } from '@renderer/store/settings' +import { SidebarIcon } from '@renderer/types' import { message } from 'antd' import { Code, FileSearch, Folder, Languages, LayoutGrid, MessageSquareQuote, Palette, Sparkle } from 'lucide-react' import { FC, useCallback, useMemo } from 'react' import { useTranslation } from 'react-i18next' import styled from 'styled-components' -import { SidebarIcon } from '../../../store/settings' - interface SidebarIconsManagerProps { visibleIcons: SidebarIcon[] disabledIcons: SidebarIcon[] diff --git a/src/renderer/src/store/migrate.ts b/src/renderer/src/store/migrate.ts index b818fae757..f83a384a46 100644 --- a/src/renderer/src/store/migrate.ts +++ b/src/renderer/src/store/migrate.ts @@ -4,6 +4,7 @@ import { DEFAULT_CONTEXTCOUNT, DEFAULT_TEMPERATURE, isMac } from '@renderer/conf import { DEFAULT_MIN_APPS } from '@renderer/config/minapps' import { isFunctionCallingModel, isNotSupportedTextDelta, SYSTEM_MODELS } from '@renderer/config/models' import { TRANSLATE_PROMPT } from '@renderer/config/prompts' +import { DEFAULT_SIDEBAR_ICONS } from '@renderer/config/sidebar' import { isSupportArrayContentProvider, isSupportDeveloperRoleProvider, @@ -32,7 +33,7 @@ import { DEFAULT_TOOL_ORDER } from './inputTools' import { initialState as llmInitialState, moveProvider } from './llm' import { mcpSlice } from './mcp' import { defaultActionItems } from './selectionStore' -import { DEFAULT_SIDEBAR_ICONS, initialState as settingsInitialState } from './settings' +import { initialState as settingsInitialState } from './settings' import { initialState as shortcutsInitialState } from './shortcuts' import { defaultWebSearchProviders } from './websearch' diff --git a/src/renderer/src/store/minapps.ts b/src/renderer/src/store/minapps.ts index cf2f194e46..95fea71a09 100644 --- a/src/renderer/src/store/minapps.ts +++ b/src/renderer/src/store/minapps.ts @@ -1,16 +1,6 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit' import { DEFAULT_MIN_APPS } from '@renderer/config/minapps' -import { MinAppType, SidebarIcon } from '@renderer/types' - -export const DEFAULT_SIDEBAR_ICONS: SidebarIcon[] = [ - 'assistants', - 'agents', - 'paintings', - 'translate', - 'minapp', - 'knowledge', - 'files' -] +import { MinAppType } from '@renderer/types' export interface MinAppsState { enabled: MinAppType[] diff --git a/src/renderer/src/store/settings.ts b/src/renderer/src/store/settings.ts index f226f990f2..ae51e9f556 100644 --- a/src/renderer/src/store/settings.ts +++ b/src/renderer/src/store/settings.ts @@ -1,5 +1,6 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit' import { TRANSLATE_PROMPT } from '@renderer/config/prompts' +import { DEFAULT_SIDEBAR_ICONS } from '@renderer/config/sidebar' import { ApiServerConfig, AssistantsSortType, @@ -10,6 +11,7 @@ import { OpenAISummaryText, PaintingProvider, S3Config, + SidebarIcon, ThemeMode, TranslateLanguageCode } from '@renderer/types' @@ -21,26 +23,8 @@ import { RemoteSyncState } from './backup' export type SendMessageShortcut = 'Enter' | 'Shift+Enter' | 'Ctrl+Enter' | 'Command+Enter' | 'Alt+Enter' -export type SidebarIcon = - | 'assistants' - | 'agents' - | 'paintings' - | 'translate' - | 'minapp' - | 'knowledge' - | 'files' - | 'code_tools' - -export const DEFAULT_SIDEBAR_ICONS: SidebarIcon[] = [ - 'assistants', - 'agents', - 'paintings', - 'translate', - 'minapp', - 'knowledge', - 'files', - 'code_tools' -] +// Re-export for backward compatibility +export { DEFAULT_SIDEBAR_ICONS } export interface NutstoreSyncRuntime extends RemoteSyncState {} diff --git a/src/renderer/src/types/index.ts b/src/renderer/src/types/index.ts index cc7427f4c1..f889056ab1 100644 --- a/src/renderer/src/types/index.ts +++ b/src/renderer/src/types/index.ts @@ -692,7 +692,7 @@ export const isAutoDetectionMethod = (method: string): method is AutoDetectionMe return Object.hasOwn(AutoDetectionMethods, method) } -export type SidebarIcon = 'assistants' | 'agents' | 'paintings' | 'translate' | 'minapp' | 'knowledge' | 'files' +export type SidebarIcon = 'assistants' | 'agents' | 'paintings' | 'translate' | 'minapp' | 'knowledge' | 'files' | 'code_tools' export type ExternalToolResult = { mcpTools?: MCPTool[]