Files
writer-work-flow/apps/web/app/projects/[id]/outline/page.tsx

36 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { notFound } from "next/navigation";
import { BackendDownNotice } from "@/components/BackendDownNotice";
import { OutlineEditor } from "@/components/outline/OutlineEditor";
import { fetchOutline, fetchProject } from "@/lib/api/server";
import type { ProjectResponse } from "@/lib/api/types";
interface PageProps {
params: Promise<{ id: string }>;
}
// 大纲编辑器页UX §6.7。Server Component 取项目 + 已存大纲GET .../outline
// 空/错误降级为空列表作为初始章节重访时显已生成的大纲OutlineEditorClient
// 仍按需触发 POST .../outline 生成/覆盖所显章节。
export default async function OutlinePage({ params }: PageProps) {
const { id } = await params;
// 仅当项目确实不存在404才判 notFound后端不可用等其它失败降级为「后端不可达」提示
// 不把整页变成「找不到页面」。次级拉取(大纲)的瞬时错误已在 fetchOutline 内降级为空。
let project: ProjectResponse;
try {
project = await fetchProject(id);
} catch (err) {
if (isNotFoundError(err)) notFound();
return <BackendDownNotice className="m-6" />;
}
const initialChapters = await fetchOutline(id);
return <OutlineEditor project={project} initialChapters={initialChapters} />;
}
// fetchProject 抛错信息形如「请求失败 404: ...」;据此区分「项目不存在」与「后端不可用」。
function isNotFoundError(err: unknown): boolean {
return err instanceof Error && err.message.includes("请求失败 404");
}