/* Copyright 2024 New Vector Ltd. Copyright 2019-2021 The Matrix.org Foundation C.I.C. Copyright 2019 Michael Telatynski <7t3chguy@gmail.com> SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only Please see LICENSE files in the repository root for full details. */ import React from "react"; import { FilesIcon } from "@vector-im/compound-design-tokens/assets/web/icons"; import { _t } from "../../../languageHandler"; import { getBlobSafeMimeType } from "../../../utils/blobs"; import BaseDialog from "./BaseDialog"; import DialogButtons from "../elements/DialogButtons"; import { fileSize } from "../../../utils/FileUtils"; interface IProps { file: File; currentIndex: number; totalFiles: number; onFinished: (uploadConfirmed: boolean, uploadAll?: boolean) => void; } export default class UploadConfirmDialog extends React.Component { private readonly objectUrl: string; private readonly mimeType: string; public static defaultProps: Partial = { totalFiles: 1, currentIndex: 0, }; public constructor(props: IProps) { super(props); // Create a fresh `Blob` for previewing (even though `File` already is // one) so we can adjust the MIME type if needed. this.mimeType = getBlobSafeMimeType(props.file.type); const blob = new Blob([props.file], { type: this.mimeType }); this.objectUrl = URL.createObjectURL(blob); } public componentWillUnmount(): void { if (this.objectUrl) URL.revokeObjectURL(this.objectUrl); } private onCancelClick = (): void => { this.props.onFinished(false); }; private onUploadClick = (): void => { this.props.onFinished(true); }; private onUploadAllClick = (): void => { this.props.onFinished(true, true); }; public render(): React.ReactNode { let title: string; if (this.props.totalFiles > 1 && this.props.currentIndex !== undefined) { title = _t("upload_file|title_progress", { current: this.props.currentIndex + 1, total: this.props.totalFiles, }); } else { title = _t("upload_file|title"); } const fileId = `mx-uploadconfirmdialog-${this.props.file.name}`; let preview: JSX.Element | undefined; let placeholder: JSX.Element | undefined; if (this.mimeType.startsWith("image/")) { preview = ( ); } else if (this.mimeType.startsWith("video/")) { preview = (