Files
TREK/client/src/components/Files/FileManagerPdfPreviewModal.tsx
T
Maurice 2a05e6d20d refactor(files): share the preview dialog frame between the PDF and Markdown previews
Both previews built the same dialog head band with the file name, the
open in tab pill and the download pill. FilePreviewDialog now draws it;
the dialog width, the body class and the icon colour stay parameters,
and each preview keeps its own body.
2026-10-09 16:15:49 +02:00

34 lines
1.3 KiB
TypeScript

import { openFile as openFileUrl } from '../../utils/fileDownload'
import type { FileManagerState } from './useFileManager'
import { FilePreviewDialog } from './FileManagerPreviewDialog'
/** A PDF read in place, in the planner's dialog: the name on the head band, open and download beside it. */
export function PdfPreviewModal(S: FileManagerState) {
const { previewFile, setPreviewFile, previewFileUrl, toast, t } = S
const close = () => setPreviewFile(null)
const openInTab = () => openFileUrl(previewFile.url, previewFile.original_name).catch(() => toast.error(t('files.openError')))
return (
<FilePreviewDialog
name={previewFile.original_name}
url={previewFile.url}
onClose={close}
onOpenInTab={openInTab}
t={t}
width="wide"
bodyClassName="flex min-h-0 flex-1 flex-col"
iconClassName="text-danger"
>
<object
data={previewFileUrl ? `${previewFileUrl}#view=FitH` : undefined}
type="application/pdf"
className="h-[74vh] w-full border-0"
title={previewFile.original_name}
>
<p className="p-6 text-center text-content-muted">
<button type="button" onClick={openInTab} className="text-content underline">{t('files.downloadPdf')}</button>
</p>
</object>
</FilePreviewDialog>
)
}