From 73524ac440412c78e2f4f3d0ff5f6462116e29f4 Mon Sep 17 00:00:00 2001 From: Talha Tahmid Date: Sun, 6 Oct 2024 10:58:27 -0500 Subject: [PATCH] trying to fix fileid --- src/app/dashboard/[fileid]/page.tsx | 19 ++++++++++++------- src/lib/actions/report.actions.ts | 22 ++++++++++------------ 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/app/dashboard/[fileid]/page.tsx b/src/app/dashboard/[fileid]/page.tsx index 752a120..bd9d449 100644 --- a/src/app/dashboard/[fileid]/page.tsx +++ b/src/app/dashboard/[fileid]/page.tsx @@ -1,6 +1,6 @@ import PdfSummary from "@/components/PdfSummary"; import PdfRenderer from "@/components/PdfRenderer"; -import { fetchReport } from "@/lib/actions/report.actions"; // Import your fetchReport function +import { fetchReport, fetchAllReportIds } from "@/lib/actions/report.actions"; // Import your fetch functions interface PageProps { params: { @@ -8,13 +8,22 @@ interface PageProps { }; } +export async function generateStaticParams() { + // Fetch all the report IDs that you want to pre-generate static pages for + const reportIds = await fetchAllReportIds(); + + // Return an array of params, each containing a report ID + return reportIds.map((id) => ({ + fileid: id, + })); +} + const Page = async ({ params }: PageProps) => { const { fileid } = params; // Fetch the report using the fileid const report = await fetchReport(fileid); - // Check if the report is found, and if not, you can handle it (e.g., show an error message) if (!report) { return (
@@ -32,16 +41,13 @@ const Page = async ({ params }: PageProps) => { return (
- {/* Left sidebar & main wrapper */}
- {/* Main area */}
- {/* Pass the fileUrl to PdfRenderer */} +
- {/* Scrollable container for PdfSummary */}
@@ -50,7 +56,6 @@ const Page = async ({ params }: PageProps) => {
); - }; export default Page; diff --git a/src/lib/actions/report.actions.ts b/src/lib/actions/report.actions.ts index 00d8fe0..6a38e51 100644 --- a/src/lib/actions/report.actions.ts +++ b/src/lib/actions/report.actions.ts @@ -28,6 +28,7 @@ export async function createReport({ fileUrl, fileId, }); + const reports = await Report.find({}, 'fileId'); await User.findOneAndUpdate( { email: author }, // Find the user by email @@ -42,23 +43,20 @@ export async function createReport({ } } -export async function fetchReport(fileId: string) { +export async function fetchAllReportIds() { try { // Connect to the database await connectToDB(); - // Find the report by fileId instead of _id - const report = await Report.findOne({ fileId: fileId }); + // Fetch all reports and return their fileId fields + const reports = await Report.find({}, 'fileId'); // Only return the fileId field - // If no report is found, throw an error - if (!report) { - throw new Error("Report not found"); - } - - // Return the report data - return report; + // Map through the results to extract fileIds + return reports.map((report) => report.fileId); } catch (error: any) { - console.error(`Error fetching report: ${error}`); - throw new Error("Error fetching report"); + console.error(`Error fetching report IDs: ${error.message}`); + throw new Error("Error fetching report IDs"); } } + +