"use client"; import { useMemo, useState } from "react"; import { ListTree, Sparkles } from "lucide-react"; import { AppShell } from "@/components/AppShell"; import { Button } from "@/components/ui/Button"; import { EmptyState } from "@/components/ui/EmptyState"; import { PageHeader } from "@/components/ui/PageHeader"; import { Select } from "@/components/ui/Select"; import { StatusNote } from "@/components/ui/StatusNote"; import { TextInput } from "@/components/ui/TextInput"; import type { OutlineChapterView, ProjectResponse } from "@/lib/api/types"; import { distinctVolumes, filterByViewVolume, groupByVolume, type ViewVolume, } from "@/lib/outline/outline"; import { useOutline } from "@/lib/outline/useOutline"; import { OutlineChapterRow } from "./OutlineChapterRow"; interface OutlineEditorProps { project: ProjectResponse; initialChapters: OutlineChapterView[]; } // 大纲编辑器主体(UX §6.7)。RSC 种入已存大纲;Client 承载生成(POST .../outline)。 // 无凭据 → 503 LLM_UNAVAILABLE 经 error 检出、引导去设置。 export function OutlineEditor({ project, initialChapters, }: OutlineEditorProps) { const { chapters, status, error, generate } = useOutline(initialChapters); const [volume, setVolume] = useState(1); // 视图卷过滤("全部" 或某卷)——只影响展示,与生成的目标卷 `volume` 解耦。 const [viewVolume, setViewVolume] = useState("all"); const availableVolumes = useMemo(() => distinctVolumes(chapters), [chapters]); const volumes = useMemo( () => groupByVolume(filterByViewVolume(chapters, viewVolume)), [chapters, viewVolume], ); const generating = status === "generating"; return (
{availableVolumes.length > 0 ? ( ) : null} setVolume(Math.max(1, Number(e.target.value) || 1)) } controlSize="sm" className="w-16" /> } /> {error ? ( {error.text} {error.actionHref ? ( <> {" "} {error.actionLabel} ) : null} ) : null}
{volumes.length === 0 ? ( 0 && viewVolume !== "all" ? `卷 ${viewVolume} 暂无大纲` : "暂无大纲" } description={ chapters.length > 0 && viewVolume !== "all" ? "切到「全部」查看其它卷,或为当前卷生成章节节拍。" : "点击「AI 排大纲」生成逐章节拍与伏笔窗口,再回到写作台逐章推进。" } action={ } /> ) : ( volumes.map((group) => (

卷 {group.volume}

    {group.chapters.map((ch) => ( ))}
)) )}
); }