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() {
|
2022-07-06 07:06:53 -04:00
|
|
|
const { pdfUrl, pdfFile, 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:
|
2022-07-06 07:06:53 -04:00
|
|
|
return <PdfJsViewer url={pdfUrl} pdfFile={pdfFile} />
|
2021-09-30 07:29:25 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default memo(PdfViewer)
|