From ba17c7e043506f8b422337b0d99fd3908343db2c Mon Sep 17 00:00:00 2001 From: Rithish Date: Fri, 8 May 2026 18:59:20 +0000 Subject: [PATCH] Fix PDF viewer initial page count bug --- src/components/newPdfViewer.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/components/newPdfViewer.tsx b/src/components/newPdfViewer.tsx index 54ad62f..68a4a0d 100644 --- a/src/components/newPdfViewer.tsx +++ b/src/components/newPdfViewer.tsx @@ -64,15 +64,17 @@ const Controls = memo(function Controls({documentId, toggleFullscreen, isFullscr const [pageNo, setPageNo] = useState(""); useEffect(() => { - if (!scrollProv) return; - const unsub = scrollProv.onPageChange(() => { + if (!scrollProv || !scrollState?.totalPages) return; + const updatePage = () => { const current = scrollProv.getCurrentPage(); - setPageNo(String(current)); - }); - const current = scrollProv.getCurrentPage(); - setPageNo(String(current)); + if (scrollState.totalPages > 0) { + setPageNo(String(current)); + } + }; + const unsub = scrollProv.onPageChange(updatePage); + updatePage(); return () => unsub(); - }, [scrollProv]); + }, [scrollProv, scrollState?.totalPages]); const pageChange = useCallback( (e: React.KeyboardEvent) => { @@ -115,7 +117,7 @@ const Controls = memo(function Controls({documentId, toggleFullscreen, isFullscr }} className="h-9 w-14 rounded border bg-[#e7e9ff] p-1 text-center text-sm [appearance:textfield] dark:bg-[#1f1f2a] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none" /> - of {totalPages ?? "..."} + {totalPages > 0 ? `of ${totalPages}` : "Loading..."} )