118 lines
3.6 KiB
TypeScript
118 lines
3.6 KiB
TypeScript
import { AppSidebar } from "@/components/app-sidebar";
|
|
import { NavActions } from "@/components/nav-actions";
|
|
import {
|
|
Breadcrumb,
|
|
BreadcrumbItem,
|
|
BreadcrumbList,
|
|
BreadcrumbPage,
|
|
} from "@/components/ui/breadcrumb";
|
|
import { Separator } from "@/components/ui/separator";
|
|
import {
|
|
SidebarInset,
|
|
SidebarProvider,
|
|
SidebarTrigger,
|
|
} from "@/components/ui/sidebar";
|
|
import { createClient } from "@/utils/supabase/server";
|
|
import { redirect } from "next/navigation";
|
|
import { remark } from "remark";
|
|
import remarkHtml from "remark-html";
|
|
|
|
export default async function DocumentPage({
|
|
params,
|
|
}: {
|
|
params: { id: string };
|
|
}) {
|
|
const supabase = await createClient();
|
|
|
|
const {
|
|
data: { user },
|
|
} = await supabase.auth.getUser();
|
|
|
|
if (!user) {
|
|
return redirect("/login");
|
|
}
|
|
|
|
// Fetch the document details based on the ID from params
|
|
const { data: document, error } = await supabase
|
|
.from("documents")
|
|
.select("*")
|
|
.eq("id", params.id)
|
|
.single();
|
|
|
|
if (error || !document) {
|
|
console.error("Error fetching document:", error);
|
|
}
|
|
|
|
// If the document doesn't exist, redirect to the documents page or handle it accordingly
|
|
if (!document) {
|
|
return redirect("/dashboard");
|
|
}
|
|
const { data: documents, error: documentsError } = await supabase
|
|
.from("documents")
|
|
.select("id, file_name, created_at, owner")
|
|
.eq("owner", user.id)
|
|
.order("created_at", { ascending: false });
|
|
|
|
if (documentsError) {
|
|
console.error("Error fetching documents:", error);
|
|
return <div>Error loading documents.</div>;
|
|
}
|
|
|
|
const pages = (document.ocr_data as any).pages.map(
|
|
(page: any) => page.markdown
|
|
);
|
|
|
|
const processedContent = await remark()
|
|
.use(remarkHtml)
|
|
.process(pages.join(" "));
|
|
|
|
return (
|
|
<SidebarProvider>
|
|
<AppSidebar
|
|
documents={documents.map((d) => {
|
|
return {
|
|
name: d.file_name,
|
|
url: `/dashboard/documents/${d.id}`,
|
|
emoji: "📄",
|
|
};
|
|
})}
|
|
/>
|
|
<SidebarInset>
|
|
<header className="flex h-14 shrink-0 items-center gap-2">
|
|
<div className="flex flex-1 items-center gap-2 px-3">
|
|
<SidebarTrigger />
|
|
<Separator
|
|
orientation="vertical"
|
|
className="mr-2 data-[orientation=vertical]:h-4"
|
|
/>
|
|
<Breadcrumb>
|
|
<BreadcrumbList>
|
|
<BreadcrumbItem>
|
|
<BreadcrumbPage className="line-clamp-1">
|
|
{document.file_name || "Document Details"}
|
|
</BreadcrumbPage>
|
|
</BreadcrumbItem>
|
|
</BreadcrumbList>
|
|
</Breadcrumb>
|
|
</div>
|
|
<div className="ml-auto px-3">
|
|
<NavActions />
|
|
</div>
|
|
</header>
|
|
<div
|
|
className="prose mx-auto px-4 py-10
|
|
text-white
|
|
prose-h1:font-semibold prose-h1:text-2xl prose-h1:mb-4 prose-h1:text-white
|
|
prose-h2:font-medium prose-h2:text-xl prose-h2:mb-3 prose-h2:text-white
|
|
prose-a:text-blue-400 hover:prose-a:underline
|
|
prose-p:leading-7 prose-p:text-gray-200
|
|
prose-blockquote:italic prose-blockquote:border-l-4 prose-blockquote:pl-4 prose-blockquote:border-gray-600 prose-blockquote:text-gray-300
|
|
prose-code:bg-gray-800 prose-code:rounded prose-code:px-1 prose-code:py-0.5 prose-code:text-gray-200
|
|
prose-img:rounded-lg prose-img:shadow-sm"
|
|
dangerouslySetInnerHTML={{ __html: String(processedContent) }}
|
|
></div>
|
|
</SidebarInset>
|
|
</SidebarProvider>
|
|
);
|
|
}
|