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 }) => {
{label}
-
>
);
};
@@ -416,9 +366,8 @@ export const MediaIDField = ({ source }) => {
}
const mxcURL = `mxc://${homeserver}/${mediaID}`;
- const uploadName = decodeURIComponent(get(record, "upload_name")?.toString());
- return ;
+ return ;
};
export const ReportMediaContent = ({ source }) => {
@@ -432,7 +381,5 @@ export const ReportMediaContent = ({ source }) => {
return null;
}
- const uploadName = decodeURIComponent(record.event_json.content.body);
-
- return ;
+ return ;
};