Files
mnote/wolai-frontend/src/app/(app)/documents/[id]/page.tsx
T

77 lines
2.9 KiB
TypeScript
Raw Normal View History

2025-11-23 10:55:04 +08:00
import { notFound, redirect } from "next/navigation";
import { DocumentShell } from "@/components/editor/document-shell";
import type { PageOptionsState, DocumentStats } from "@/types/page-options";
2026-01-17 10:12:53 +08:00
import { isConvexEnabled } from "@/lib/convex/enabled";
2026-01-18 19:01:31 +08:00
import { getAuthedConvexClient } from "@/lib/convex/route";
2026-01-17 10:12:53 +08:00
import { api } from "@/lib/convex/api";
2025-11-23 10:55:04 +08:00
interface DocumentPageProps {
params: Promise<{ id: string }>;
2026-01-10 10:35:21 +08:00
// eslint-disable-next-line @typescript-eslint/no-explicit-any
searchParams?: Promise<Record<string, any>>;
2025-11-23 10:55:04 +08:00
}
2026-01-10 10:35:21 +08:00
export default async function DocumentPage({ params, searchParams }: DocumentPageProps) {
2025-11-23 10:55:04 +08:00
const { id } = await params;
2026-01-10 10:35:21 +08:00
const resolvedSearch = (await searchParams) ?? {};
const openTableIdRaw = resolvedSearch?.openTableId;
const openTableId = typeof openTableIdRaw === "string" ? openTableIdRaw : null;
2026-01-17 10:12:53 +08:00
if (isConvexEnabled()) {
2026-01-18 19:01:31 +08:00
const { client } = await getAuthedConvexClient();
const doc = await client.query(api.documents.getMeta, { id });
2026-01-17 10:12:53 +08:00
if (!doc) {
notFound();
}
2026-01-22 18:53:20 +08:00
const readOnly = (doc as any).can_edit === false;
2026-01-24 12:32:51 +08:00
const disableDownload = Boolean((doc as any).disable_download);
const disableCopy = Boolean((doc as any).disable_copy);
2026-01-17 10:12:53 +08:00
const initialOptions: PageOptionsState = {
wideLayout: doc.wide_layout ?? false,
smallText: doc.use_small_text ?? false,
showHeadingNumbers: doc.show_heading_numbers ?? true,
showToc: doc.show_toc ?? false,
showStructure: doc.show_structure ?? false,
protectEditing: doc.protect_editing ?? false,
showWordCount: doc.show_word_count ?? true,
2026-02-01 08:47:40 +08:00
collapseBacklinks: (doc as any).collapse_backlinks ?? false,
pageFont: (doc as any).page_font ?? "default",
layoutDensity: (doc as any).layout_density ?? "normal",
hideChildPages: (doc as any).hide_child_pages ?? false,
showBlockRefCount: (doc as any).show_block_ref_count ?? false,
embedDefaultBlockId: (doc as any).embed_default_block_id ?? null,
2026-01-17 10:12:53 +08:00
};
const initialStats: DocumentStats = {
wordCount: doc.word_count ?? 0,
characterCount: doc.character_count ?? 0,
blockCount: doc.block_count ?? 0,
2026-02-01 08:47:40 +08:00
todoTotal: (doc as any).todo_total ?? (doc as any).todo_total_count ?? 0,
todoDone: (doc as any).todo_done ?? (doc as any).todo_done_count ?? 0,
2026-01-17 10:12:53 +08:00
};
return (
<div className="flex h-screen flex-col">
<div className="min-h-0 flex-1">
<DocumentShell
documentId={doc.id}
workspaceId={doc.workspace_id}
title={doc.title ?? "无标题"}
updatedAt={doc.updated_at}
initialContent={null}
initialOptions={initialOptions}
initialStats={initialStats}
openTableId={openTableId}
2026-01-22 18:53:20 +08:00
readOnly={readOnly}
2026-01-24 12:32:51 +08:00
disableDownload={disableDownload}
disableCopy={disableCopy}
2026-01-17 10:12:53 +08:00
/>
</div>
</div>
);
}
2026-01-18 19:01:31 +08:00
redirect("/auth");
2025-11-23 10:55:04 +08:00
}