From 8a769c535ba8a3031f856b5abfa52f7272b07bb2 Mon Sep 17 00:00:00 2001 From: workbuddy-mac13 Date: Sat, 28 Nov 2026 20:55:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(settings):=20=E4=BE=A7=E6=A0=8F=E5=85=A5?= =?UTF-8?q?=E5=8F=A3=E6=8A=98=E5=8F=A0=E6=B8=85=E5=8D=95=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=A1=B9=E5=8F=AF=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原先「默认折叠哪些左栏入口」是源码常量(DEFAULT_COLLAPSED_PANELS)。现在在 设置 → 侧边卡片 → 常规 的顶部新增「折叠的侧栏入口」区块:每个已知入口一个复选框 + 「应用并刷新」按钮,勾选结果直接写宿主的 pin 存储。 - 新增 src/client/collapsed-panels-setting.tsx(读 localStorage 初值 → 勾选 → 写回 + 刷新) - 写入时把标记键置为 'custom',启动时的默认集合合并逻辑遇到 'custom' 即不再插手, 用户的选择不会被默认值覆盖;反之未接管时仍按默认集合补齐缺项 - 词条加 zh + en(其余语言按 t() 规则回落 en) 候选入口:插件市场 dsh-market / 上下文洞察 dsh-context / 任务看板 task-board / 代码评审 forge-review(未安装的入口不会出现在侧栏,勾了也无副作用) --- src/client/SideCardSection.tsx | 7 ++ src/client/collapsed-panels-setting.tsx | 119 ++++++++++++++++++++++++ src/client/index.tsx | 3 + src/client/locales.ts | 6 ++ 4 files changed, 135 insertions(+) create mode 100644 src/client/collapsed-panels-setting.tsx diff --git a/src/client/SideCardSection.tsx b/src/client/SideCardSection.tsx index c9503acc..844159d6 100644 --- a/src/client/SideCardSection.tsx +++ b/src/client/SideCardSection.tsx @@ -65,6 +65,7 @@ import { CLUE_PREFS_ID, CLUE_WINDOW_SURFACE_SETTING, type SidebarPrefs } from '. import { api } from './api.ts' import { parsePrefs, syncClueWindowSurface } from './prefs.ts' import { AddPluginModal, type PluginKind } from './add-plugin-modal.tsx' +import { CollapsedPanelsSetting } from './collapsed-panels-setting.tsx' import { t } from './locales.ts' import type { SidebarStore } from './state.ts' import { mergeGuideEntries, type NativeGuideCatalog, type NativeGuideEntry } from './native/guide-catalog.ts' @@ -1890,6 +1891,12 @@ export function SideCardSection(props: SideCardSectionInjected & Partial

{t('settingsGeneralTitle')}

+ {/* 侧栏入口折叠: which left-sidebar entries stay out of the way. + The host folds an entry into its More menu when the entry's + panel id is in the host's pin storage; this block is where the + user picks that set. */} + + typeof id === 'string') : [] + } catch { + return [] + } +} + +/** + * Write the folded set and reload, so the host's pin store picks it up. + * + * @param ids - the panel ids to fold away. + */ +function writeUnpinned(ids: string[]): void { + if (typeof localStorage === 'undefined') return + try { + localStorage.setItem(PIN_KEY, JSON.stringify({ unpinned: ids })) + localStorage.setItem(MARK_KEY, CUSTOM_MARK) + location.reload() + } catch { + // A storage that refuses the write keeps the current layout. + } +} + +/** + * The setting block: one checkbox per known entry plus an apply button. + * + * @returns the setting rows. + */ +export function CollapsedPanelsSetting(): React.ReactNode { + const [selected, setSelected] = useState([]) + + useEffect(() => { + setSelected(readUnpinned()) + }, []) + + function toggle(id: string, next: boolean): void { + setSelected(current => (next ? [...current.filter(entry => entry !== id), id] : current.filter(entry => entry !== id))) + } + + return ( +
+
{t('settingsCollapsedPanelsTitle')}
+ {CANDIDATE_PANELS.map(panel => ( + + toggle(panel.id, event.currentTarget.checked)} + /> + + ))} + +
+ ) +} diff --git a/src/client/index.tsx b/src/client/index.tsx index 808b5c0e..963b7ac1 100644 --- a/src/client/index.tsx +++ b/src/client/index.tsx @@ -107,6 +107,9 @@ function ensureDefaultCollapsedPanels(): void { if (typeof localStorage === 'undefined') return try { const mark = localStorage.getItem(PANEL_PIN_MARK_KEY) + // `custom` = the user manages the folded set in the settings block; the + // default set must not creep back in. + if (mark === 'custom') return if (mark === DEFAULT_COLLAPSED_PANELS.join(',')) return const raw = localStorage.getItem(PANEL_PIN_KEY) const current = raw === null ? [] : (JSON.parse(raw)?.unpinned ?? []) diff --git a/src/client/locales.ts b/src/client/locales.ts index 735764a1..3eb5d6fc 100644 --- a/src/client/locales.ts +++ b/src/client/locales.ts @@ -506,6 +506,9 @@ export const zh = { settingsMobileTreeTitle: '窄屏时任务页默认树状图', settingsMobileTreeDesc: '手机 / 窄屏下任务页默认用经典树,而不是工作流图;页内切换仍可临时改成图', settingsGeneralTitle: '常规', + settingsCollapsedPanelsTitle: '折叠的侧栏入口', + settingsCollapsedPanelsDesc: '勾选后该入口从左侧栏收进「更多」菜单,随时可在那里钉回。', + settingsCollapsedPanelsApply: '应用并刷新', settingsPopup: '功能设置', settingsViewerCatchAll: '兜底:任意文件', viewerMarkdown: 'Markdown', @@ -1779,6 +1782,9 @@ export const en: Record = { settingsMobileTreeTitle: 'Default the Tasks page to the tree', settingsMobileTreeDesc: "On a phone / narrow viewport the Tasks page opens as the classic tree instead of the workflow graph; the in-page toggle still switches it ad hoc", settingsGeneralTitle: 'General', + settingsCollapsedPanelsTitle: 'Folded sidebar entries', + settingsCollapsedPanelsDesc: 'Checked entries move out of the left sidebar into the More menu; pin them back from there.', + settingsCollapsedPanelsApply: 'Apply and refresh', settingsPopup: 'Feature settings', settingsViewerCatchAll: 'Catch-all: any file', viewerMarkdown: 'Markdown',