From dbece64d4d7c8effffe5a24c75b662b652d74e05 Mon Sep 17 00:00:00 2001 From: Yaojia Wang Date: Fri, 10 Jul 2026 18:14:49 +0200 Subject: [PATCH] =?UTF-8?q?feat(frontend):=20=E3=80=8C=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E3=80=8D=E5=88=97=E5=8F=AF=E6=8A=98=E5=8F=A0=E3=80=81=E8=AE=B0?= =?UTF-8?q?=E5=BF=86=E6=8A=98=E5=8F=A0=E7=8A=B6=E6=80=81=EF=BC=88UX=20P2-2?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit useChapterListCollapse 用 localStorage 记忆折叠态(SSR 首帧恒展开避免 hydration 不一致);收起降为带展开按钮的窄轨、让宽给正文,展开时标题旁加收起按钮;三栏栅格据折叠态切列宽,章节列表/高亮/切章导航全保留。 --- apps/web/components/workbench/ChapterList.tsx | 63 ++++++++++++++++-- apps/web/components/workbench/Workbench.tsx | 13 +++- .../workbench/useChapterListCollapse.test.ts | 64 +++++++++++++++++++ .../lib/workbench/useChapterListCollapse.ts | 46 +++++++++++++ 4 files changed, 178 insertions(+), 8 deletions(-) create mode 100644 apps/web/lib/workbench/useChapterListCollapse.test.ts create mode 100644 apps/web/lib/workbench/useChapterListCollapse.ts diff --git a/apps/web/components/workbench/ChapterList.tsx b/apps/web/components/workbench/ChapterList.tsx index 6074a85..07653f7 100644 --- a/apps/web/components/workbench/ChapterList.tsx +++ b/apps/web/components/workbench/ChapterList.tsx @@ -1,6 +1,8 @@ import Link from "next/link"; +import { PanelLeftClose, PanelLeftOpen } from "lucide-react"; import { buildChapterEntries, type ChapterEntry } from "@/lib/workbench/chapter"; +import { focusRing } from "@/lib/ui/variants"; interface ChapterListProps { projectId: string; @@ -9,36 +11,83 @@ interface ChapterListProps { currentChapterNo: number; } -// 左栏目录(UX §6.3):列出大纲全部章节 + 当前章,点击切换写作章号(`?chapter=N`)。 -// 桌面 aside 包裹;移动端经 Workbench 抽屉复用 ChapterListContent。 +interface DesktopChapterListProps extends ChapterListProps { + // 目录列收起态(P2-2):收起时只留一条带「展开」按钮的窄轨,让宽给正文。 + collapsed: boolean; + onToggle: () => void; +} + +// 左栏目录(UX §6.3 / P2-2):列出大纲全部章节 + 当前章,点击切换写作章号(`?chapter=N`)。 +// 桌面 aside 包裹,可收起为窄轨;移动端经 Workbench 抽屉复用 ChapterListContent(不带折叠)。 export function ChapterList({ projectId, chapters, currentChapterNo, -}: ChapterListProps) { + collapsed, + onToggle, +}: DesktopChapterListProps) { + if (collapsed) { + return ( + + ); + } return ( ); } +interface ChapterListContentProps extends ChapterListProps { + // 桌面列传入 → 目录标题旁显示「收起」按钮;移动抽屉不传(抽屉自带关闭)。 + onCollapse?: () => void; +} + export function ChapterListContent({ projectId, chapters, currentChapterNo, -}: ChapterListProps) { + onCollapse, +}: ChapterListContentProps) { const entries = buildChapterEntries(chapters, currentChapterNo); const hasOutline = chapters.length > 0; return ( <> -

- 目录 -

+
+

+ 目录 +

+ {onCollapse ? ( + + ) : null} +