2019-04-01 16:42:41 +01:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2019-2024 New Vector Ltd.
|
2019-04-01 16:42:41 +01:00
|
|
|
|
2024-09-09 14:57:16 +01:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
|
|
|
|
|
Please see LICENSE files in the repository root for full details.
|
2019-04-01 16:42:41 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
2021-10-22 17:23:32 -05:00
|
|
|
|
2019-04-01 16:42:41 +01:00
|
|
|
import { _t } from "../../../languageHandler";
|
|
|
|
|
import ContentMessages from "../../../ContentMessages";
|
2021-09-05 08:31:06 +02:00
|
|
|
import BaseDialog from "./BaseDialog";
|
|
|
|
|
import DialogButtons from "../elements/DialogButtons";
|
2023-04-11 19:18:41 +05:30
|
|
|
import { fileSize } from "../../../utils/FileUtils";
|
2021-09-05 08:31:06 +02:00
|
|
|
|
2023-02-28 10:31:48 +00:00
|
|
|
interface IProps {
|
2021-09-05 08:31:06 +02:00
|
|
|
badFiles: File[];
|
|
|
|
|
totalFiles: number;
|
|
|
|
|
contentMessages: ContentMessages;
|
2023-02-28 10:31:48 +00:00
|
|
|
onFinished(upload?: boolean): void;
|
2021-09-05 08:31:06 +02:00
|
|
|
}
|
2019-04-01 16:42:41 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Tells the user about files we know cannot be uploaded before we even try uploading
|
|
|
|
|
* them. This is named fairly generically but the only thing we check right now is
|
|
|
|
|
* the size of the file.
|
|
|
|
|
*/
|
2021-09-05 08:31:06 +02:00
|
|
|
export default class UploadFailureDialog extends React.Component<IProps> {
|
|
|
|
|
private onCancelClick = (): void => {
|
2019-04-01 16:42:41 +01:00
|
|
|
this.props.onFinished(false);
|
2021-09-05 08:31:06 +02:00
|
|
|
};
|
2019-04-01 16:42:41 +01:00
|
|
|
|
2021-09-05 08:31:06 +02:00
|
|
|
private onUploadClick = (): void => {
|
2019-04-01 16:42:41 +01:00
|
|
|
this.props.onFinished(true);
|
2021-09-05 08:31:06 +02:00
|
|
|
};
|
2019-04-01 16:42:41 +01:00
|
|
|
|
2023-02-13 17:01:43 +00:00
|
|
|
public render(): React.ReactNode {
|
2019-04-01 16:42:41 +01:00
|
|
|
let message;
|
|
|
|
|
let preview;
|
|
|
|
|
let buttons;
|
|
|
|
|
if (this.props.totalFiles === 1 && this.props.badFiles.length === 1) {
|
|
|
|
|
message = _t(
|
2023-10-03 19:17:26 +01:00
|
|
|
"upload_file|error_file_too_large",
|
2019-04-01 16:42:41 +01:00
|
|
|
{
|
2023-09-07 17:40:51 +00:00
|
|
|
limit: fileSize(this.props.contentMessages.getUploadLimit()!),
|
2023-04-11 19:18:41 +05:30
|
|
|
sizeOfThisFile: fileSize(this.props.badFiles[0].size),
|
2019-04-01 16:42:41 +01:00
|
|
|
},
|
|
|
|
|
{
|
2024-09-13 12:09:41 +01:00
|
|
|
b: (sub) => <strong>{sub}</strong>,
|
2019-04-01 16:42:41 +01:00
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
buttons = (
|
|
|
|
|
<DialogButtons
|
2023-08-22 20:55:15 +01:00
|
|
|
primaryButton={_t("action|ok")}
|
2019-04-01 16:42:41 +01:00
|
|
|
hasCancel={false}
|
2021-09-05 08:31:06 +02:00
|
|
|
onPrimaryButtonClick={this.onCancelClick}
|
2019-04-01 16:42:41 +01:00
|
|
|
focus={true}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
} else if (this.props.totalFiles === this.props.badFiles.length) {
|
|
|
|
|
message = _t(
|
2023-10-03 19:17:26 +01:00
|
|
|
"upload_file|error_files_too_large",
|
2019-04-01 16:42:41 +01:00
|
|
|
{
|
2023-09-07 17:40:51 +00:00
|
|
|
limit: fileSize(this.props.contentMessages.getUploadLimit()!),
|
2019-04-01 16:42:41 +01:00
|
|
|
},
|
|
|
|
|
{
|
2024-09-13 12:09:41 +01:00
|
|
|
b: (sub) => <strong>{sub}</strong>,
|
2019-04-01 16:42:41 +01:00
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
buttons = (
|
|
|
|
|
<DialogButtons
|
2023-08-22 20:55:15 +01:00
|
|
|
primaryButton={_t("action|ok")}
|
2019-04-01 16:42:41 +01:00
|
|
|
hasCancel={false}
|
2021-09-05 08:31:06 +02:00
|
|
|
onPrimaryButtonClick={this.onCancelClick}
|
2019-04-01 16:42:41 +01:00
|
|
|
focus={true}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
message = _t(
|
2023-10-03 19:17:26 +01:00
|
|
|
"upload_file|error_some_files_too_large",
|
2019-04-01 16:42:41 +01:00
|
|
|
{
|
2023-09-07 17:40:51 +00:00
|
|
|
limit: fileSize(this.props.contentMessages.getUploadLimit()!),
|
2019-04-01 16:42:41 +01:00
|
|
|
},
|
|
|
|
|
{
|
2024-09-13 12:09:41 +01:00
|
|
|
b: (sub) => <strong>{sub}</strong>,
|
2019-04-01 16:42:41 +01:00
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
const howManyOthers = this.props.totalFiles - this.props.badFiles.length;
|
|
|
|
|
buttons = (
|
|
|
|
|
<DialogButtons
|
2023-10-03 19:17:26 +01:00
|
|
|
primaryButton={_t("upload_file|upload_n_others_button", { count: howManyOthers })}
|
2021-09-05 08:31:06 +02:00
|
|
|
onPrimaryButtonClick={this.onUploadClick}
|
2019-04-01 16:42:41 +01:00
|
|
|
hasCancel={true}
|
2023-10-03 19:17:26 +01:00
|
|
|
cancelButton={_t("upload_file|cancel_all_button")}
|
2021-09-05 08:31:06 +02:00
|
|
|
onCancel={this.onCancelClick}
|
2019-04-01 16:42:41 +01:00
|
|
|
focus={true}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<BaseDialog
|
|
|
|
|
className="mx_UploadFailureDialog"
|
2021-09-05 08:31:06 +02:00
|
|
|
onFinished={this.onCancelClick}
|
2023-10-03 19:17:26 +01:00
|
|
|
title={_t("upload_file|error_title")}
|
2019-04-01 16:42:41 +01:00
|
|
|
contentId="mx_Dialog_content"
|
|
|
|
|
>
|
|
|
|
|
<div id="mx_Dialog_content">
|
2021-07-19 22:43:11 +01:00
|
|
|
{message}
|
|
|
|
|
{preview}
|
2019-04-01 16:42:41 +01:00
|
|
|
</div>
|
|
|
|
|
|
2021-07-19 22:43:11 +01:00
|
|
|
{buttons}
|
2019-04-01 16:42:41 +01:00
|
|
|
</BaseDialog>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|