Fix: Mergekonflikt in pdfViewer.tsx bereinigt HOFFENTLICH

pull/47/head
Abdulrahman Dabbagh 2025-06-04 23:09:30 +02:00
parent 9ac2ff2226
commit 08eb77d9d7
1 changed files with 15 additions and 19 deletions

View File

@ -2,9 +2,9 @@ import { useEffect, useRef, useState, useCallback } from "react";
import { Document, Page, pdfjs } from "react-pdf"; import { Document, Page, pdfjs } from "react-pdf";
import "react-pdf/dist/esm/Page/AnnotationLayer.css"; import "react-pdf/dist/esm/Page/AnnotationLayer.css";
import "react-pdf/dist/esm/Page/TextLayer.css"; import "react-pdf/dist/esm/Page/TextLayer.css";
import { Box, IconButton } from "@mui/material";
import ArrowCircleLeftIcon from "@mui/icons-material/ArrowCircleLeft"; import ArrowCircleLeftIcon from "@mui/icons-material/ArrowCircleLeft";
import ArrowCircleRightIcon from "@mui/icons-material/ArrowCircleRight"; import ArrowCircleRightIcon from "@mui/icons-material/ArrowCircleRight";
import { Box, IconButton } from "@mui/material";
pdfjs.GlobalWorkerOptions.workerSrc = new URL( pdfjs.GlobalWorkerOptions.workerSrc = new URL(
"pdfjs-dist/build/pdf.worker.min.mjs", "pdfjs-dist/build/pdf.worker.min.mjs",
@ -20,34 +20,28 @@ export default function PDFViewer({ pitchBookId, currentPage }: PDFViewerProps)
const [numPages, setNumPages] = useState<number | null>(null); const [numPages, setNumPages] = useState<number | null>(null);
const [pageNumber, setPageNumber] = useState(currentPage || 1); const [pageNumber, setPageNumber] = useState(currentPage || 1);
const [containerWidth, setContainerWidth] = useState<number | null>(null); const [containerWidth, setContainerWidth] = useState<number | null>(null);
const containerRef = useRef<HTMLDivElement>(null);
const [highlightLabels, setHighlightLabels] = useState<string[]>([]); const [highlightLabels, setHighlightLabels] = useState<string[]>([]);
const containerRef = useRef<HTMLDivElement>(null);
const onDocumentLoadSuccess = ({ numPages }: { numPages: number }) => { const onDocumentLoadSuccess = ({ numPages }: { numPages: number }) => {
setNumPages(numPages); setNumPages(numPages);
}; };
// Aktuelle Containergröße berechnen // Update PDF width on resize
useEffect(() => { useEffect(() => {
const updateWidth = () => { const updateWidth = () => {
if (containerRef.current) { if (containerRef.current) {
setContainerWidth(containerRef.current.offsetWidth); setContainerWidth(containerRef.current.offsetWidth);
} }
}; };
updateWidth(); updateWidth();
window.addEventListener("resize", updateWidth); window.addEventListener("resize", updateWidth);
return () => window.removeEventListener("resize", updateWidth); return () => window.removeEventListener("resize", updateWidth);
}, []); }, []);
// Seite ändern, wenn prop sich ändert // Highlight search logic
useEffect(() => {
if (currentPage && currentPage !== pageNumber) {
setPageNumber(currentPage);
}
}, [currentPage]);
// Highlight-Logik
useEffect(() => { useEffect(() => {
setHighlightLabels(["LTV", "Fondsmanager", "Risikoprofil"]); setHighlightLabels(["LTV", "Fondsmanager", "Risikoprofil"]);
}, []); }, []);
@ -65,6 +59,13 @@ export default function PDFViewer({ pitchBookId, currentPage }: PDFViewerProps)
[highlightLabels] [highlightLabels]
); );
// Update page if prop changes
useEffect(() => {
if (currentPage && currentPage !== pageNumber) {
setPageNumber(currentPage);
}
}, [currentPage]);
return ( return (
<Box <Box
display="flex" display="flex"
@ -89,9 +90,7 @@ export default function PDFViewer({ pitchBookId, currentPage }: PDFViewerProps)
<Document <Document
file={`http://localhost:5050/api/pitch_book/${pitchBookId}/download`} file={`http://localhost:5050/api/pitch_book/${pitchBookId}/download`}
onLoadSuccess={onDocumentLoadSuccess} onLoadSuccess={onDocumentLoadSuccess}
onLoadError={(error) => onLoadError={(error) => console.error("Fehler beim Laden:", error)}
console.error("Es gab ein Fehler beim Laden des PDFs:", error)
}
onSourceError={(error) => console.error("Ungültige PDF:", error)} onSourceError={(error) => console.error("Ungültige PDF:", error)}
> >
{containerWidth && ( {containerWidth && (
@ -110,10 +109,7 @@ export default function PDFViewer({ pitchBookId, currentPage }: PDFViewerProps)
justifyContent="center" justifyContent="center"
gap={1} gap={1}
> >
<IconButton <IconButton disabled={pageNumber <= 1} onClick={() => setPageNumber((p) => p - 1)}>
disabled={pageNumber <= 1}
onClick={() => setPageNumber((p) => p - 1)}
>
<ArrowCircleLeftIcon fontSize="large" /> <ArrowCircleLeftIcon fontSize="large" />
</IconButton> </IconButton>
<span> <span>