From 9062a6afb1e6f76a1f398cba0928d5431249d383 Mon Sep 17 00:00:00 2001 From: Borislav Pantaleev Date: Thu, 3 Oct 2024 00:52:07 +0300 Subject: [PATCH] Remove Dialog window for image preview, open all media in new tab --- src/components/media.tsx | 73 ++++++---------------------------------- 1 file changed, 10 insertions(+), 63 deletions(-) diff --git a/src/components/media.tsx b/src/components/media.tsx index afbc1c6..9fc8eed 100644 --- a/src/components/media.tsx +++ b/src/components/media.tsx @@ -314,42 +314,24 @@ export const QuarantineMediaButton = (props: ButtonProps) => { ); }; -export const ViewMediaButton = ({ mxcURL, uploadName, label }) => { +export const ViewMediaButton = ({ mxcURL, label }) => { const translate = useTranslate(); - const [open, setOpen] = useState(false); - const [blobURL, setBlobURL] = useState(""); - - const handleOpen = () => setOpen(true); - const handleClose = () => { - setOpen(false); - if (blobURL) { - URL.revokeObjectURL(blobURL); - } - }; - - const forceDownload = (url: string, filename: string) => { + const openFileInNewTab = (blobURL: string) => { const anchorElement = document.createElement("a"); - anchorElement.href = url; - anchorElement.download = filename; + anchorElement.href = blobURL; + anchorElement.target = "_blank"; document.body.appendChild(anchorElement); anchorElement.click(); document.body.removeChild(anchorElement); - URL.revokeObjectURL(blobURL); + setTimeout(() => URL.revokeObjectURL(blobURL), 10); }; - const handleFile = async () => { + const previewFile = async () => { const response = await fetchAuthenticatedMedia(mxcURL, "original"); const blob = await response.blob(); const blobURL = URL.createObjectURL(blob); - setBlobURL(blobURL); - - const mimeType = blob.type; - if (!mimeType.startsWith("image/")) { - forceDownload(blobURL, uploadName); - } else { - handleOpen(); - } + openFileInNewTab(blobURL); }; return ( @@ -358,7 +340,7 @@ export const ViewMediaButton = ({ mxcURL, uploadName, label }) => {