From 261c0c6f72e6234c763dcff5491797a6b70844a8 Mon Sep 17 00:00:00 2001 From: Yogesh Date: Fri, 17 Apr 2026 19:00:59 +0530 Subject: [PATCH 1/2] fix: mount viewport loader --- src/components/newPdfViewer.tsx | 61 +++++++++++++++++---------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/src/components/newPdfViewer.tsx b/src/components/newPdfViewer.tsx index aee6105..93e5c85 100644 --- a/src/components/newPdfViewer.tsx +++ b/src/components/newPdfViewer.tsx @@ -15,7 +15,6 @@ import { downloadFile } from "../lib/utils/download"; import { Button } from "./ui/button"; import ShareButton from "./ShareButton"; import ReportButton from "./ReportButton"; -import path from 'path/win32'; interface ControlProps { documentId: string; @@ -255,7 +254,6 @@ function WheelZoom({ documentId, viewerRef }: WheelZoomProps) { const rafId = useRef(null); const curZoom = useRef(1); - // Stay in sync with zoom from anywhere (buttons, keyboard, etc.) useEffect(() => { if (!zoomProv) return; curZoom.current = zoomProv.getState().currentZoomLevel; @@ -283,7 +281,7 @@ function WheelZoom({ documentId, viewerRef }: WheelZoomProps) { zoomProv.requestZoom(target) curZoom.current = target; } else { - zoomProv.requestZoomBy(clamped); // mouse wheel, relative is fine + zoomProv.requestZoomBy(clamped); } accumulatedDelta.current = 0; @@ -351,9 +349,13 @@ export default function PDFViewer({ url, name }: PdfViewerProps) { }), ], [url, name]); - if (isLoading || !engine) { - return
Loading PDF Engine...
; - } +if (isLoading || !engine) { + return ( +
+ Loading PDF… +
+ ); +} return (
} - {({ isLoaded }) => - isLoaded && ( - - ( -
- -
- )} - /> -
- ) - } -
+ {({ isLoaded }) => ( + <> + {!isLoaded && ( +
+ Loading PDF… +
+ )} + + ( +
+ +
+ )} + /> +
+ + )} + {(!isMobile || isFullscreen) && ( )} - ) } From 40ab9e5fa89eed7e4c4bf7f50f55873a8c530cca Mon Sep 17 00:00:00 2001 From: Yogesh Date: Fri, 17 Apr 2026 22:43:05 +0530 Subject: [PATCH 2/2] fix: loader comp, smooth transition, loading message --- src/components/newPdfViewer.tsx | 61 +++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 10 deletions(-) diff --git a/src/components/newPdfViewer.tsx b/src/components/newPdfViewer.tsx index 93e5c85..d516449 100644 --- a/src/components/newPdfViewer.tsx +++ b/src/components/newPdfViewer.tsx @@ -304,6 +304,44 @@ function WheelZoom({ documentId, viewerRef }: WheelZoomProps) { return null; } +function useLoadingMessage(messages: string[], interval = 2200) { + const [index, setIndex] = useState(0); + const [visible, setVisible] = useState(true); + + useEffect(() => { + const timer = setInterval(() => { + setVisible(false); + setTimeout(() => { + setIndex(i => (i + 1) % messages.length); + setVisible(true); + }, 400); + }, interval); + return () => clearInterval(timer); + }, [messages, interval]); + + return { message: messages[index], visible }; +} + +const LOADING_MESSAGES = [ + "Loading document", + "Preparing pages", + "Almost there", +]; + +export function Loader() { + const { message, visible } = useLoadingMessage(LOADING_MESSAGES); + return ( +
+
+ + {message} + +
+ ); +} export default function PDFViewer({ url, name }: PdfViewerProps) { const { engine, isLoading } = usePdfiumEngine(); const {isMobile, isSmall} = useBreakpoint(); @@ -351,9 +389,7 @@ export default function PDFViewer({ url, name }: PdfViewerProps) { if (isLoading || !engine) { return ( -
- Loading PDF… -
+ ); } @@ -378,13 +414,18 @@ if (isLoading || !engine) { isSmall={isSmall} />} - {({ isLoaded }) => ( - <> - {!isLoaded && ( -
- Loading PDF… -
- )} + {({ isLoaded }) => ( + <> +
+ +