70 lines
2.2 KiB
TypeScript
70 lines
2.2 KiB
TypeScript
import { DialogTitle } from "@headlessui/react";
|
|
import { lazy, Suspense } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { MediaDto } from "~/application/dtos/entities/MediaDto";
|
|
import ButtonSecondary from "../buttons/ButtonSecondary";
|
|
import XIcon from "../icons/XIcon";
|
|
import OpenModal from "../modals/OpenModal";
|
|
import DownloadIcon from "../icons/DownloadIcon";
|
|
|
|
const PdfViewer = lazy(() => import("../pdf/PdfViewer"));
|
|
|
|
interface Props {
|
|
item: MediaDto;
|
|
onClose: () => void;
|
|
onDownload: () => void;
|
|
}
|
|
|
|
export default function PreviewMediaModal({ item, onClose, onDownload }: Props) {
|
|
const { t } = useTranslation();
|
|
|
|
function isPdf() {
|
|
return item.type.endsWith("pdf");
|
|
}
|
|
|
|
function isImage() {
|
|
return item.type.includes("image");
|
|
}
|
|
|
|
return (
|
|
<OpenModal onClose={onClose}>
|
|
<div>
|
|
{!item ? (
|
|
<div>{t("shared.notSet")}</div>
|
|
) : (
|
|
<div className="">
|
|
<div className="flex items-center justify-between space-x-2">
|
|
<DialogTitle as="h3" className="text-foreground truncate text-lg font-medium leading-6">
|
|
{item.title}
|
|
</DialogTitle>
|
|
<div className="flex space-x-2">
|
|
<ButtonSecondary type="button" onClick={onDownload}>
|
|
<DownloadIcon className="h-4 w-4" />
|
|
</ButtonSecondary>
|
|
<ButtonSecondary type="button" onClick={onClose}>
|
|
<XIcon className="h-4 w-4" />
|
|
</ButtonSecondary>
|
|
</div>
|
|
</div>
|
|
<div className="mt-4 space-y-3">
|
|
{isPdf() ? (
|
|
<div>
|
|
<Suspense fallback={<div className="h-96 animate-pulse rounded-md bg-gray-100" />}>
|
|
<PdfViewer file={item.publicUrl ?? item.file} canDownload={false} />
|
|
</Suspense>
|
|
</div>
|
|
) : isImage() ? (
|
|
<div>
|
|
<img alt={item.title} className="mx-auto h-96 object-contain" src={item.publicUrl ?? item.file} />
|
|
</div>
|
|
) : (
|
|
<div>{t("components.media.notPdfOrImage")}</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</OpenModal>
|
|
);
|
|
}
|