Convert UploadFailureDialog to TS

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner 2021-09-05 08:31:06 +02:00
parent 3c9ded5a9a
commit 0b9255f5ee
No known key found for this signature in database
GPG key ID: 55C211A1226CB17D

View file

@ -17,11 +17,18 @@ limitations under the License.
import filesize from 'filesize'; import filesize from 'filesize';
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types';
import * as sdk from '../../../index';
import { _t } from '../../../languageHandler'; import { _t } from '../../../languageHandler';
import ContentMessages from '../../../ContentMessages'; import ContentMessages from '../../../ContentMessages';
import { replaceableComponent } from "../../../utils/replaceableComponent"; import { replaceableComponent } from "../../../utils/replaceableComponent";
import BaseDialog from "./BaseDialog";
import DialogButtons from "../elements/DialogButtons";
interface IProps {
badFiles: File[];
totalFiles: number;
contentMessages: ContentMessages;
onFinished: (success: boolean) => void;
}
/* /*
* Tells the user about files we know cannot be uploaded before we even try uploading * Tells the user about files we know cannot be uploaded before we even try uploading
@ -29,26 +36,16 @@ import { replaceableComponent } from "../../../utils/replaceableComponent";
* the size of the file. * the size of the file.
*/ */
@replaceableComponent("views.dialogs.UploadFailureDialog") @replaceableComponent("views.dialogs.UploadFailureDialog")
export default class UploadFailureDialog extends React.Component { export default class UploadFailureDialog extends React.Component<IProps> {
static propTypes = { private onCancelClick = (): void => {
badFiles: PropTypes.arrayOf(PropTypes.object).isRequired,
totalFiles: PropTypes.number.isRequired,
contentMessages: PropTypes.instanceOf(ContentMessages).isRequired,
onFinished: PropTypes.func.isRequired,
}
_onCancelClick = () => {
this.props.onFinished(false); this.props.onFinished(false);
} };
_onUploadClick = () => { private onUploadClick = (): void => {
this.props.onFinished(true); this.props.onFinished(true);
} };
render() {
const BaseDialog = sdk.getComponent('views.dialogs.BaseDialog');
const DialogButtons = sdk.getComponent('views.elements.DialogButtons');
public render(): JSX.Element {
let message; let message;
let preview; let preview;
let buttons; let buttons;
@ -65,7 +62,7 @@ export default class UploadFailureDialog extends React.Component {
); );
buttons = <DialogButtons primaryButton={_t('OK')} buttons = <DialogButtons primaryButton={_t('OK')}
hasCancel={false} hasCancel={false}
onPrimaryButtonClick={this._onCancelClick} onPrimaryButtonClick={this.onCancelClick}
focus={true} focus={true}
/>; />;
} else if (this.props.totalFiles === this.props.badFiles.length) { } else if (this.props.totalFiles === this.props.badFiles.length) {
@ -80,7 +77,7 @@ export default class UploadFailureDialog extends React.Component {
); );
buttons = <DialogButtons primaryButton={_t('OK')} buttons = <DialogButtons primaryButton={_t('OK')}
hasCancel={false} hasCancel={false}
onPrimaryButtonClick={this._onCancelClick} onPrimaryButtonClick={this.onCancelClick}
focus={true} focus={true}
/>; />;
} else { } else {
@ -96,17 +93,17 @@ export default class UploadFailureDialog extends React.Component {
const howManyOthers = this.props.totalFiles - this.props.badFiles.length; const howManyOthers = this.props.totalFiles - this.props.badFiles.length;
buttons = <DialogButtons buttons = <DialogButtons
primaryButton={_t('Upload %(count)s other files', { count: howManyOthers })} primaryButton={_t('Upload %(count)s other files', { count: howManyOthers })}
onPrimaryButtonClick={this._onUploadClick} onPrimaryButtonClick={this.onUploadClick}
hasCancel={true} hasCancel={true}
cancelButton={_t("Cancel All")} cancelButton={_t("Cancel All")}
onCancel={this._onCancelClick} onCancel={this.onCancelClick}
focus={true} focus={true}
/>; />;
} }
return ( return (
<BaseDialog className='mx_UploadFailureDialog' <BaseDialog className='mx_UploadFailureDialog'
onFinished={this._onCancelClick} onFinished={this.onCancelClick}
title={_t("Upload Error")} title={_t("Upload Error")}
contentId='mx_Dialog_content' contentId='mx_Dialog_content'
> >