diff --git a/frontend/src/components/PdfViewer.tsx b/frontend/src/components/PdfViewer.tsx index 7089716..b13aaa6 100644 --- a/frontend/src/components/PdfViewer.tsx +++ b/frontend/src/components/PdfViewer.tsx @@ -1,156 +1,11 @@ -'use client'; - -import { useState, useEffect, useRef } from 'react'; -import { Document, Page, pdfjs } from 'react-pdf'; -import { ZoomIn, ZoomOut, Loader2 } from 'lucide-react'; -import { useInView } from 'react-intersection-observer'; -import 'react-pdf/dist/Page/AnnotationLayer.css'; -import 'react-pdf/dist/Page/TextLayer.css'; - -pdfjs.GlobalWorkerOptions.workerSrc = new URL( - 'pdfjs-dist/build/pdf.worker.min.mjs', - import.meta.url, -).toString(); - -function LazyPage({ pageNumber, scale, containerWidth }: { pageNumber: number; scale: number; containerWidth: number }) { - const { ref, inView } = useInView({ - triggerOnce: false, - rootMargin: '150% 0px', - }); - - const pageWidth = Math.min(containerWidth * 0.9, 900); - const estimatedHeight = pageWidth * 1.414 * scale; - - return ( -
- {inView ? ( - - -
- } - /> - ) : ( -
- )} -
- ); -} - export default function PdfViewer({ url }: { url: string }) { - const [numPages, setNumPages] = useState(); - const [scale, setScale] = useState(1.0); - const [loadError, setLoadError] = useState(null); - const containerRef = useRef(null); - const [containerWidth, setContainerWidth] = useState(800); - - useEffect(() => { - const el = containerRef.current; - if (!el) return; - const ro = new ResizeObserver(([entry]) => { - setContainerWidth(entry.contentRect.width); - }); - ro.observe(el); - return () => ro.disconnect(); - }, []); - - function onDocumentLoadSuccess({ numPages }: { numPages: number }): void { - setNumPages(numPages); - setLoadError(null); - } - - if (loadError) { - return ( -
- {loadError} - - Download Instead - -
- ); - } - return ( -
- {/* PDF Toolbar */} -
-
- - {numPages ? `${numPages} page${numPages !== 1 ? 's' : ''}` : 'Loading...'} - -
-
- - - {Math.round(scale * 100)}% - - -
-
- - {/* PDF Content */} -
- { - console.error('Failed to load PDF:', error); - setLoadError('Failed to load PDF file.'); - }} - loading={ -
- - Loading PDF... -
- } - className="flex flex-col items-center gap-2 w-full" - > - {numPages && Array.from(new Array(numPages), (_, index) => ( - - ))} -
-
+
+