2021-10-21 06:31:51 -04:00
|
|
|
import { lazy, memo } from 'react'
|
2022-03-31 07:22:36 -04:00
|
|
|
import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
const PdfJsViewer = lazy(() =>
|
|
|
|
import(/* webpackChunkName: "pdf-js-viewer" */ './pdf-js-viewer')
|
|
|
|
)
|
|
|
|
|
|
|
|
function PdfViewer() {
|
2021-10-21 06:31:51 -04:00
|
|
|
const { pdfUrl, pdfViewer } = useCompileContext()
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
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)
|