From 08eb77d9d7d7d52f37dde8aa3fe20915b3883d96 Mon Sep 17 00:00:00 2001 From: Abdulraahman Dabbagh <1924466@stud.hs-mannheim.de> Date: Wed, 4 Jun 2025 23:09:30 +0200 Subject: [PATCH] Fix: Mergekonflikt in pdfViewer.tsx bereinigt HOFFENTLICH --- project/frontend/src/components/pdfViewer.tsx | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/project/frontend/src/components/pdfViewer.tsx b/project/frontend/src/components/pdfViewer.tsx index b1069fb..d872aa4 100644 --- a/project/frontend/src/components/pdfViewer.tsx +++ b/project/frontend/src/components/pdfViewer.tsx @@ -2,9 +2,9 @@ import { useEffect, useRef, useState, useCallback } from "react"; import { Document, Page, pdfjs } from "react-pdf"; import "react-pdf/dist/esm/Page/AnnotationLayer.css"; import "react-pdf/dist/esm/Page/TextLayer.css"; +import { Box, IconButton } from "@mui/material"; import ArrowCircleLeftIcon from "@mui/icons-material/ArrowCircleLeft"; import ArrowCircleRightIcon from "@mui/icons-material/ArrowCircleRight"; -import { Box, IconButton } from "@mui/material"; pdfjs.GlobalWorkerOptions.workerSrc = new URL( "pdfjs-dist/build/pdf.worker.min.mjs", @@ -20,34 +20,28 @@ export default function PDFViewer({ pitchBookId, currentPage }: PDFViewerProps) const [numPages, setNumPages] = useState(null); const [pageNumber, setPageNumber] = useState(currentPage || 1); const [containerWidth, setContainerWidth] = useState(null); - const containerRef = useRef(null); - const [highlightLabels, setHighlightLabels] = useState([]); + const containerRef = useRef(null); + const onDocumentLoadSuccess = ({ numPages }: { numPages: number }) => { setNumPages(numPages); }; - // Aktuelle Containergröße berechnen + // Update PDF width on resize useEffect(() => { const updateWidth = () => { if (containerRef.current) { setContainerWidth(containerRef.current.offsetWidth); } }; + updateWidth(); window.addEventListener("resize", updateWidth); return () => window.removeEventListener("resize", updateWidth); }, []); - // Seite ändern, wenn prop sich ändert - useEffect(() => { - if (currentPage && currentPage !== pageNumber) { - setPageNumber(currentPage); - } - }, [currentPage]); - - // Highlight-Logik + // Highlight search logic useEffect(() => { setHighlightLabels(["LTV", "Fondsmanager", "Risikoprofil"]); }, []); @@ -65,6 +59,13 @@ export default function PDFViewer({ pitchBookId, currentPage }: PDFViewerProps) [highlightLabels] ); + // Update page if prop changes + useEffect(() => { + if (currentPage && currentPage !== pageNumber) { + setPageNumber(currentPage); + } + }, [currentPage]); + return ( - console.error("Es gab ein Fehler beim Laden des PDFs:", error) - } + onLoadError={(error) => console.error("Fehler beim Laden:", error)} onSourceError={(error) => console.error("Ungültige PDF:", error)} > {containerWidth && ( @@ -110,10 +109,7 @@ export default function PDFViewer({ pitchBookId, currentPage }: PDFViewerProps) justifyContent="center" gap={1} > - setPageNumber((p) => p - 1)} - > + setPageNumber((p) => p - 1)}>