mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
f7ef2532e0
* Only hide the compile logs pane when toggled off * Handle PDF preview on toggle between split and full-width views GitOrigin-RevId: 9ceca8a06a22abfa78f245e1ae5d24af98215906
38 lines
872 B
JavaScript
38 lines
872 B
JavaScript
import useScopeValue from '../../../shared/hooks/use-scope-value'
|
|
import { lazy, memo, useEffect } from 'react'
|
|
import { useCompileContext } from '../../../shared/context/compile-context'
|
|
|
|
const PdfJsViewer = lazy(() =>
|
|
import(/* webpackChunkName: "pdf-js-viewer" */ './pdf-js-viewer')
|
|
)
|
|
|
|
const params = new URLSearchParams(window.location.search)
|
|
|
|
function PdfViewer() {
|
|
const [pdfViewer, setPdfViewer] = useScopeValue('settings.pdfViewer')
|
|
|
|
useEffect(() => {
|
|
const viewer = params.get('viewer')
|
|
|
|
if (viewer) {
|
|
setPdfViewer(viewer)
|
|
}
|
|
}, [setPdfViewer])
|
|
|
|
const { pdfUrl } = useCompileContext()
|
|
|
|
if (!pdfUrl) {
|
|
return null
|
|
}
|
|
|
|
switch (pdfViewer) {
|
|
case 'native':
|
|
return <iframe title="PDF Preview" src={pdfUrl} />
|
|
|
|
case 'pdfjs':
|
|
default:
|
|
return <PdfJsViewer url={pdfUrl} />
|
|
}
|
|
}
|
|
|
|
export default memo(PdfViewer)
|