2022-08-27 14:32:20 +02:00
|
|
|
import React, { useRef } from 'react';
|
2022-08-04 11:12:22 +02:00
|
|
|
import useIsFocused from './hooks/useIsFocused';
|
2022-08-27 14:32:20 +02:00
|
|
|
import usePdfData from './hooks/usePdfData';
|
2022-08-04 11:12:22 +02:00
|
|
|
import VerticalPages from './VerticalPages';
|
|
|
|
|
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) {
|
|
|
|
const pdf = usePdfData(props.pdfPath);
|
2022-08-04 11:12:22 +02:00
|
|
|
const isFocused = useIsFocused();
|
|
|
|
const containerEl = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
|
|
if (!pdf) {
|
|
|
|
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-27 14:32:20 +02:00
|
|
|
<VerticalPages pdf={pdf} isDarkTheme={props.isDarkTheme} anchorPage={props.anchorPage} pdfId={props.pdfId} rememberScroll={true}
|
|
|
|
container={containerEl} showPageNumbers={true} />
|
2022-08-04 11:12:22 +02:00
|
|
|
</div>
|
|
|
|
<div className='app-bottom-bar'>
|
|
|
|
<div className='pdf-info'>
|
|
|
|
{pdf.pageCount} pages
|
|
|
|
</div>
|
|
|
|
<div>{isFocused ? '' : 'Click to enable scroll'}</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|