From d439a081e9c98f2c7d707315aeb3887d3322fac1 Mon Sep 17 00:00:00 2001 From: Aamir Azad Date: Fri, 28 Jun 2024 17:15:20 +0530 Subject: [PATCH] Mobile is being hard for some reason --- .../(.)paperless/document/[id]/modal.tsx | 2 +- src/components/document-viewer.tsx | 34 ++++++++++--------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/app/@modal/(.)paperless/document/[id]/modal.tsx b/src/app/@modal/(.)paperless/document/[id]/modal.tsx index 2f9fed9..6ccac67 100644 --- a/src/app/@modal/(.)paperless/document/[id]/modal.tsx +++ b/src/app/@modal/(.)paperless/document/[id]/modal.tsx @@ -24,7 +24,7 @@ export function Modal({ children }: { children: React.ReactNode }) { className="absolute h-screen w-screen bg-zinc-900/60" onClose={onDismiss} > -
{children}
+
{children}
, document.getElementById("modal-root")!, ); diff --git a/src/components/document-viewer.tsx b/src/components/document-viewer.tsx index 7e97a3c..7dd328e 100644 --- a/src/components/document-viewer.tsx +++ b/src/components/document-viewer.tsx @@ -45,37 +45,39 @@ export default function DocumentViewer(props: { id: number }) { const fetchData = async () => { setLoading(true); - const objectUrl = await getPaperlessDocument(props.id); - if (objectUrl) { - setPdfUrl(objectUrl); + try { + const objectUrl = await getPaperlessDocument(props.id); + if (objectUrl) { + setPdfUrl(objectUrl); + } else { + setPdfUrl(null); + } + } catch (error) { + console.error("An error occurred:", error); + setPdfUrl(null); + } finally { setLoading(false); - // Cleanup function to revoke URL when component unmounts or pdfUrl changes - return () => URL.revokeObjectURL(objectUrl); - } else { } }; - - fetchData().catch((error) => { - console.error("An error occurred:", error); - }); - }, [props.id]); // Dependency array to refetch if id changes + fetchData(); + }, []); // Dependency array to refetch if id changes if (loading) { return Loading...; } if (!pdfUrl) { - return

Failure

; + return

Failed to get document

; } return (
-
-
+
+