2022-09-05 13:35:38 +02:00
|
|
|
import React, { useRef, useState, useCallback } from 'react';
|
2022-08-04 11:12:22 +02:00
|
|
|
import useIsFocused from './hooks/useIsFocused';
|
2022-09-05 13:35:38 +02:00
|
|
|
import usePdfDocument from './hooks/usePdfDocument';
|
2022-08-04 11:12:22 +02:00
|
|
|
import VerticalPages from './VerticalPages';
|
2022-08-28 13:18:51 +02:00
|
|
|
import ZoomControls from './ui/ZoomControls';
|
2022-09-05 13:35:38 +02:00
|
|
|
import { DownloadButton, PrintButton } from './ui/IconButtons';
|
|
|
|
|
|
|
|
require('./miniViewer.css');
|
2022-08-04 11:12:22 +02:00
|
|
|
|
2022-08-27 14:32:20 +02:00
|
|
|
export interface MiniViewerAppProps {
|
|
|
|
pdfPath: string;
|
|
|
|
isDarkTheme: boolean;
|
|
|
|
anchorPage: number;
|
|
|
|
pdfId: string;
|
|
|
|
}
|
2022-08-04 11:12:22 +02:00
|
|
|
|
2022-08-27 14:32:20 +02:00
|
|
|
export default function MiniViewerApp(props: MiniViewerAppProps) {
|
2022-09-05 13:35:38 +02:00
|
|
|
const pdfDocument = usePdfDocument(props.pdfPath);
|
2022-08-04 11:12:22 +02:00
|
|
|
const isFocused = useIsFocused();
|
2022-08-28 13:18:51 +02:00
|
|
|
const [zoom, setZoom] = useState<number>(1);
|
2022-08-04 11:12:22 +02:00
|
|
|
const containerEl = useRef<HTMLDivElement>(null);
|
2022-09-05 13:35:38 +02:00
|
|
|
const [activePage, setActivePage] = useState(1);
|
|
|
|
|
|
|
|
const onActivePageChange = useCallback((page: number) => {
|
|
|
|
setActivePage(page);
|
|
|
|
}, []);
|
2022-08-04 11:12:22 +02:00
|
|
|
|
2022-09-05 13:35:38 +02:00
|
|
|
if (!pdfDocument) {
|
2022-08-04 11:12:22 +02:00
|
|
|
return (
|
|
|
|
<div className="mini-app loading">
|
|
|
|
<div>Loading pdf..</div>
|
|
|
|
</div>);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={`mini-app${isFocused ? ' focused' : ''}`}>
|
|
|
|
<div className={`app-pages${isFocused ? ' focused' : ''}`} ref={containerEl}>
|
2022-08-28 13:18:51 +02:00
|
|
|
<VerticalPages
|
2022-09-05 13:35:38 +02:00
|
|
|
pdfDocument={pdfDocument}
|
2022-08-28 13:18:51 +02:00
|
|
|
isDarkTheme={props.isDarkTheme}
|
|
|
|
anchorPage={props.anchorPage}
|
|
|
|
pdfId={props.pdfId}
|
|
|
|
rememberScroll={true}
|
|
|
|
container={containerEl}
|
|
|
|
showPageNumbers={true}
|
2022-09-05 13:35:38 +02:00
|
|
|
zoom={zoom}
|
|
|
|
pageGap={2}
|
|
|
|
onActivePageChange={onActivePageChange} />
|
2022-08-04 11:12:22 +02:00
|
|
|
</div>
|
|
|
|
<div className='app-bottom-bar'>
|
|
|
|
<div className='pdf-info'>
|
2022-09-05 13:35:38 +02:00
|
|
|
<div style={{ paddingRight: '0.4rem' }}>{activePage}/{pdfDocument.pageCount} pages</div>
|
2022-08-28 13:18:51 +02:00
|
|
|
<ZoomControls onChange={setZoom} zoom={zoom} />
|
2022-09-05 13:35:38 +02:00
|
|
|
<PrintButton onClick={pdfDocument?.printPdf}/>
|
|
|
|
<DownloadButton onClick={pdfDocument?.downloadPdf}/>
|
2022-08-04 11:12:22 +02:00
|
|
|
</div>
|
2022-09-05 13:35:38 +02:00
|
|
|
<div className="can-hide">{isFocused ? '' : 'Click to enable scroll'}</div>
|
2022-08-04 11:12:22 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|