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

43 lines
1.6 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 { ForeshadowBoard } from "@/components/foreshadow/ForeshadowBoard";
import { fetchForeshadow, fetchProject } from "@/lib/api/server";
import type { ForeshadowView, ProjectResponse } from "@/lib/api/types";
interface PageProps {
params: Promise<{ id: string }>;
}
// 伏笔看板页UX §6.8。Server Component 取项目 + 全量伏笔GET .../foreshadow
// ForeshadowBoardClient按 status 分四泳道并承载登记/状态变更交互。
export default async function ForeshadowPage({ params }: PageProps) {
const { id } = await params;
// 仅当项目确实不存在404才判 notFound后端不可用等其它失败降级为「后端不可达」提示
// 不把整页变成「找不到页面」。
let project: ProjectResponse;
try {
project = await fetchProject(id);
} catch (err) {
if (isNotFoundError(err)) notFound();
return <BackendDownNotice className="m-6" />;
}
// 伏笔看板GET .../foreshadow。瞬时错误降级为空看板不阻塞进页。
let initialItems: ForeshadowView[] = [];
try {
const board = await fetchForeshadow(id);
initialItems = board.foreshadow ?? [];
} catch {
initialItems = [];
}
return <ForeshadowBoard project={project} initialItems={initialItems} />;
}
// fetchProject 抛错信息形如「请求失败 404: ...」;据此区分「项目不存在」与「后端不可用」。
function isNotFoundError(err: unknown): boolean {
return err instanceof Error && err.message.includes("请求失败 404");
}