import type { FC } from 'react' import { createPortal } from 'react-dom' import 'react-pdf-highlighter/dist/style.css' import { PdfHighlighter, PdfLoader } from 'react-pdf-highlighter' import { t } from 'i18next' import { RiCloseLine, RiZoomInLine, RiZoomOutLine } from '@remixicon/react' import React, { useState } from 'react' import { useHotkeys } from 'react-hotkeys-hook' import Loading from '@/app/components/base/loading' import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' import Tooltip from '@/app/components/base/tooltip' type PdfPreviewProps = { url: string onCancel: () => void } const PdfPreview: FC = ({ url, onCancel, }) => { const media = useBreakpoints() const [scale, setScale] = useState(1) const [position, setPosition] = useState({ x: 0, y: 0 }) const isMobile = media === MediaType.mobile const zoomIn = () => { setScale(prevScale => Math.min(prevScale * 1.2, 15)) setPosition({ x: position.x - 50, y: position.y - 50 }) } const zoomOut = () => { setScale((prevScale) => { const newScale = Math.max(prevScale / 1.2, 0.5) if (newScale === 1) setPosition({ x: 0, y: 0 }) else setPosition({ x: position.x + 50, y: position.y + 50 }) return newScale }) } useHotkeys('esc', onCancel) useHotkeys('up', zoomIn) useHotkeys('down', zoomOut) return createPortal(
e.stopPropagation()} tabIndex={-1} >
} > {(pdfDocument) => { return ( event.altKey} scrollRef={() => { }} onScrollChange={() => { }} onSelectionFinished={() => null} highlightTransform={() => { return
}} highlights={[]} /> ) }}
, document.body, ) } export default PdfPreview