Fix: Mergekonflikt in pdfViewer.tsx bereinigt HOFFENTLICH
parent
9ac2ff2226
commit
08eb77d9d7
|
|
@ -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<number | null>(null);
|
||||
const [pageNumber, setPageNumber] = useState(currentPage || 1);
|
||||
const [containerWidth, setContainerWidth] = useState<number | null>(null);
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const [highlightLabels, setHighlightLabels] = useState<string[]>([]);
|
||||
|
||||
const containerRef = useRef<HTMLDivElement>(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 (
|
||||
<Box
|
||||
display="flex"
|
||||
|
|
@ -89,9 +90,7 @@ export default function PDFViewer({ pitchBookId, currentPage }: PDFViewerProps)
|
|||
<Document
|
||||
file={`http://localhost:5050/api/pitch_book/${pitchBookId}/download`}
|
||||
onLoadSuccess={onDocumentLoadSuccess}
|
||||
onLoadError={(error) =>
|
||||
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}
|
||||
>
|
||||
<IconButton
|
||||
disabled={pageNumber <= 1}
|
||||
onClick={() => setPageNumber((p) => p - 1)}
|
||||
>
|
||||
<IconButton disabled={pageNumber <= 1} onClick={() => setPageNumber((p) => p - 1)}>
|
||||
<ArrowCircleLeftIcon fontSize="large" />
|
||||
</IconButton>
|
||||
<span>
|
||||
|
|
|
|||
Loading…
Reference in New Issue