diff --git a/src/app/@modal/(.)paperless/document/[id]/page.tsx b/src/app/@modal/(.)paperless/document/[id]/page.tsx
index 8c7acb9..04cdcb7 100644
--- a/src/app/@modal/(.)paperless/document/[id]/page.tsx
+++ b/src/app/@modal/(.)paperless/document/[id]/page.tsx
@@ -1,20 +1,9 @@
-import DocumentPreview from "@/components/document-preview";
-import { Modal } from "@/components/modal";
+import DocumentModal from "@/components/document-modal";
export default function ModalDocumentPage({
params,
}: {
params: { id: number };
}) {
- return (
-
-
-
- );
+ return ;
}
diff --git a/src/app/actions.ts b/src/app/actions.ts
index c229080..33c691c 100644
--- a/src/app/actions.ts
+++ b/src/app/actions.ts
@@ -47,34 +47,4 @@ export async function getUserData() {
});
return userData;
-}
-
-/*
-Paperless
-| _ \ __ _ _ __ ___ _ __| | ___ ___ ___
-| |_) / _` | '_ \ / _ | '__| |/ _ / __/ __|
-| __| (_| | |_) | __| | | | __\__ \__ \
-|_| \__,_| .__/ \___|_| |_|\___|___|___/
- |_|
-*/
-
-export async function getPaperlessDocuments(query: string) {
- const userData = await getUserData();
-
- if (!query || query == "null" || query.length < 3 || !userData) return null;
-
- const response = await fetch(
- `${userData.paperlessURL}/api/documents/?query=${query}&page=1&page_size=10&truncate_content=true`,
- {
- method: "GET",
- headers: {
- "Content-Type": "application/json",
- Authorization: `Token ${userData.paperlessToken}`,
- },
- },
- );
-
- const data = (await response.json()) as PaperlessDocumentsType;
-
- return data;
-}
+}
\ No newline at end of file
diff --git a/src/app/paperless/document/[id]/page.tsx b/src/app/paperless/document/[id]/page.tsx
index d005031..71a025d 100644
--- a/src/app/paperless/document/[id]/page.tsx
+++ b/src/app/paperless/document/[id]/page.tsx
@@ -1,18 +1,19 @@
"use client";
-import { useRouter } from "next/navigation";
-import BodyMessage from "@/components/body-message";
+import DocumentPreview from "@/components/document-preview";
export default function FullPageDocumentPage({
params,
}: {
params: { id: number };
}) {
- const router = useRouter();
- router.replace(`/paperless/details/${params.id}`);
return (
-
- Redirecting ...
+
+
);
}
diff --git a/src/app/paperless/page.tsx b/src/app/paperless/page.tsx
index 795d983..6477644 100644
--- a/src/app/paperless/page.tsx
+++ b/src/app/paperless/page.tsx
@@ -22,12 +22,35 @@ import {
QueryClient,
} from "@tanstack/react-query";
import LoadingSpinner from "@/components/loading-spinner";
-import { getPaperlessDocuments, getUserData } from "@/app/actions";
+import { getUserData } from "@/app/actions";
import Link from "next/link";
import OpenInternalLink from "@/components/internal-link";
+import type { PaperlessDocumentsType } from "@/types";
const queryClient = new QueryClient();
+async function getPaperlessDocuments(query: string) {
+ const userData = await getUserData();
+
+ if (!query || query == "null" || query.length < 3 || !userData) return null;
+
+ const response = await fetch(
+ `${userData.paperlessURL}/api/documents/?query=${query}&page=1&page_size=10&truncate_content=true`,
+ {
+ method: "GET",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Token ${userData.paperlessToken}`,
+ },
+ },
+ );
+
+ const data = (await response.json()) as PaperlessDocumentsType;
+
+ return data;
+}
+
+
function DocumentsSearch() {
const formSchema = z.object({
query: z.string().min(3).max(256),
diff --git a/src/components/document-details.tsx b/src/components/document-details.tsx
index 0fc954e..c76ea67 100644
--- a/src/components/document-details.tsx
+++ b/src/components/document-details.tsx
@@ -90,21 +90,22 @@ const fetchUserData = async (): Promise => {
async function getPaperlessDocumentData(id: number, userData: UsersTableType) {
try {
- const url = `${userData.paperlessURL}/api/documents/${id}/`;
+ const url = `${userData.paperlessURL}/api/documents/${id}/&page=1&page_size=10&truncate_content=true`;
const response = await fetch(url, {
headers: {
Authorization: `Token ${userData.paperlessToken}`,
},
});
+ console.log(response);
if (response.ok) {
const data = (await response.json()) as PaperlessDocumentType[];
return data[0];
} else {
- console.error("Failed to fetch PDF");
+ console.error("Failed to fetch PD dataF");
return null;
}
} catch (error) {
- console.error("Error fetching PDF:", error);
+ console.error("Error fetching PDF data:", error);
return null;
}
}
@@ -139,9 +140,7 @@ function DocumentDetailsInner(props: { id: number }) {
if (isUserDataLoading || isdocumentDataLoading || isPdfUrlLoading) {
return Loading...;
- }
-
- if (!userData || !documentData) {
+ } else if (!userData || !documentData || !pdfUrl) {
return Error;
}
diff --git a/src/components/document-modal.tsx b/src/components/document-modal.tsx
new file mode 100644
index 0000000..8c7acb9
--- /dev/null
+++ b/src/components/document-modal.tsx
@@ -0,0 +1,20 @@
+import DocumentPreview from "@/components/document-preview";
+import { Modal } from "@/components/modal";
+
+export default function ModalDocumentPage({
+ params,
+}: {
+ params: { id: number };
+}) {
+ return (
+
+
+
+ );
+}
diff --git a/src/components/document-preview.tsx b/src/components/document-preview.tsx
index d90e8ff..9c4cb89 100644
--- a/src/components/document-preview.tsx
+++ b/src/components/document-preview.tsx
@@ -8,7 +8,6 @@ import {
import type { AdviceAPIType } from "@/types";
import OpenInternalLink from "./internal-link";
import type { UsersTableType } from "@/server/db/schema";
-import { Button } from "./ui/button";
import BodyMessage from "./body-message";
import { buttonVariants } from "./ui/button";
@@ -82,6 +81,8 @@ function Preview(props: { id: number }) {
const { data: userData, isLoading: isUserDataLoading } = useQuery({
queryKey: ["userData"],
queryFn: fetchUserData,
+ staleTime: 24 * 60 * 60 * 1000, // 1 day in milliseconds
+ refetchOnWindowFocus: false,
});
const { data: pdfUrl, isLoading: isPdfUrlLoading } = useQuery({
@@ -96,12 +97,11 @@ function Preview(props: { id: number }) {
if (isPdfUrlLoading ?? isUserDataLoading) {
return ;
- }
-
- if (!pdfUrl || !userData) {
+ } else if (!pdfUrl || !userData) {
return Failed to get document;
}
- return ;
+
+ return ;
}
export default function DocumentPreview(props: { id: number }) {