diff --git a/src/components/document-details.tsx b/src/components/document-details.tsx index c76ea67..37e798b 100644 --- a/src/components/document-details.tsx +++ b/src/components/document-details.tsx @@ -90,7 +90,7 @@ const fetchUserData = async (): Promise => { async function getPaperlessDocumentData(id: number, userData: UsersTableType) { try { - const url = `${userData.paperlessURL}/api/documents/${id}/&page=1&page_size=10&truncate_content=true`; + const url = `${userData.paperlessURL}/api/documents/${id}/?truncate_content=true`; const response = await fetch(url, { headers: { Authorization: `Token ${userData.paperlessToken}`, @@ -98,8 +98,8 @@ async function getPaperlessDocumentData(id: number, userData: UsersTableType) { }); console.log(response); if (response.ok) { - const data = (await response.json()) as PaperlessDocumentType[]; - return data[0]; + const data = (await response.json()) as PaperlessDocumentType; + return data; } else { console.error("Failed to fetch PD dataF"); return null; @@ -121,18 +121,22 @@ function DocumentDetailsInner(props: { id: number }) { }); const { data: pdfUrl, isLoading: isPdfUrlLoading } = useQuery({ - queryKey: ["pdfUrl", props.id, userData], // Include id and paperlessURL in the query key + queryKey: ["pdfUrl", props.id, userData], // Include id and userData in the query key queryFn: async () => { - return await getPaperlessDocument(props.id, userData!); + const result = await getPaperlessDocument(props.id, userData!); + console.log("Fetched PDF URL:", result); + return result; }, enabled: !!userData, refetchOnWindowFocus: false, }); const { data: documentData, isLoading: isdocumentDataLoading } = useQuery({ - queryKey: ["pdfData", props.id, userData], // Include id and paperlessURL in the query key + queryKey: ["documentData", props.id, userData], // Include id and userData in the query key queryFn: async () => { - return await getPaperlessDocumentData(props.id, userData!); + const result = await getPaperlessDocumentData(props.id, userData!); + console.log("Fetched Document Data:", result); + return result; }, enabled: !!userData, refetchOnWindowFocus: false, @@ -143,12 +147,19 @@ function DocumentDetailsInner(props: { id: number }) { } else if (!userData || !documentData || !pdfUrl) { return Error; } - return (
-
{documentData?.title}
+
+ {documentData?.title} + +
+ + Delete diff --git a/src/components/document-preview.tsx b/src/components/document-preview.tsx index 9c4cb89..3e1d605 100644 --- a/src/components/document-preview.tsx +++ b/src/components/document-preview.tsx @@ -108,12 +108,12 @@ export default function DocumentPreview(props: { id: number }) { return ( - Open full page - + ); }