Convert UploadConfirmDialog to TSX
parent
6e0c7611c3
commit
437f13cf76
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2019 New Vector Ltd
|
Copyright 2019, 2021 The Matrix.org Foundation C.I.C.
|
||||||
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@ -16,20 +16,21 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import * as sdk from '../../../index';
|
import * as sdk from '../../../index';
|
||||||
import { _t } from '../../../languageHandler';
|
import { _t } from '../../../languageHandler';
|
||||||
import filesize from "filesize";
|
import filesize from "filesize";
|
||||||
import {replaceableComponent} from "../../../utils/replaceableComponent";
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
||||||
|
|
||||||
|
interface IProps {
|
||||||
|
file: File;
|
||||||
|
currentIndex: number;
|
||||||
|
totalFiles?: number;
|
||||||
|
onFinished: (uploadConfirmed: boolean, uploadAll?: boolean) => void;
|
||||||
|
}
|
||||||
|
|
||||||
@replaceableComponent("views.dialogs.UploadConfirmDialog")
|
@replaceableComponent("views.dialogs.UploadConfirmDialog")
|
||||||
export default class UploadConfirmDialog extends React.Component {
|
export default class UploadConfirmDialog extends React.Component<IProps> {
|
||||||
static propTypes = {
|
private objectUrl: string;
|
||||||
file: PropTypes.object.isRequired,
|
|
||||||
currentIndex: PropTypes.number,
|
|
||||||
totalFiles: PropTypes.number,
|
|
||||||
onFinished: PropTypes.func.isRequired,
|
|
||||||
}
|
|
||||||
|
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
totalFiles: 1,
|
totalFiles: 1,
|
||||||
|
@ -38,22 +39,22 @@ export default class UploadConfirmDialog extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this._objectUrl = URL.createObjectURL(props.file);
|
this.objectUrl = URL.createObjectURL(props.file);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
if (this._objectUrl) URL.revokeObjectURL(this._objectUrl);
|
if (this.objectUrl) URL.revokeObjectURL(this.objectUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onCancelClick = () => {
|
private onCancelClick = () => {
|
||||||
this.props.onFinished(false);
|
this.props.onFinished(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onUploadClick = () => {
|
private onUploadClick = () => {
|
||||||
this.props.onFinished(true);
|
this.props.onFinished(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onUploadAllClick = () => {
|
private onUploadAllClick = () => {
|
||||||
this.props.onFinished(true, true);
|
this.props.onFinished(true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +79,7 @@ export default class UploadConfirmDialog extends React.Component {
|
||||||
if (this.props.file.type.startsWith('image/')) {
|
if (this.props.file.type.startsWith('image/')) {
|
||||||
preview = <div className="mx_UploadConfirmDialog_previewOuter">
|
preview = <div className="mx_UploadConfirmDialog_previewOuter">
|
||||||
<div className="mx_UploadConfirmDialog_previewInner">
|
<div className="mx_UploadConfirmDialog_previewInner">
|
||||||
<div><img className="mx_UploadConfirmDialog_imagePreview" src={this._objectUrl} /></div>
|
<div><img className="mx_UploadConfirmDialog_imagePreview" src={this.objectUrl} /></div>
|
||||||
<div>{this.props.file.name} ({filesize(this.props.file.size)})</div>
|
<div>{this.props.file.name} ({filesize(this.props.file.size)})</div>
|
||||||
</div>
|
</div>
|
||||||
</div>;
|
</div>;
|
||||||
|
@ -95,7 +96,7 @@ export default class UploadConfirmDialog extends React.Component {
|
||||||
|
|
||||||
let uploadAllButton;
|
let uploadAllButton;
|
||||||
if (this.props.currentIndex + 1 < this.props.totalFiles) {
|
if (this.props.currentIndex + 1 < this.props.totalFiles) {
|
||||||
uploadAllButton = <button onClick={this._onUploadAllClick}>
|
uploadAllButton = <button onClick={this.onUploadAllClick}>
|
||||||
{_t("Upload all")}
|
{_t("Upload all")}
|
||||||
</button>;
|
</button>;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +104,7 @@ export default class UploadConfirmDialog extends React.Component {
|
||||||
return (
|
return (
|
||||||
<BaseDialog className='mx_UploadConfirmDialog'
|
<BaseDialog className='mx_UploadConfirmDialog'
|
||||||
fixedWidth={false}
|
fixedWidth={false}
|
||||||
onFinished={this._onCancelClick}
|
onFinished={this.onCancelClick}
|
||||||
title={title}
|
title={title}
|
||||||
contentId='mx_Dialog_content'
|
contentId='mx_Dialog_content'
|
||||||
>
|
>
|
||||||
|
@ -113,7 +114,7 @@ export default class UploadConfirmDialog extends React.Component {
|
||||||
|
|
||||||
<DialogButtons primaryButton={_t('Upload')}
|
<DialogButtons primaryButton={_t('Upload')}
|
||||||
hasCancel={false}
|
hasCancel={false}
|
||||||
onPrimaryButtonClick={this._onUploadClick}
|
onPrimaryButtonClick={this.onUploadClick}
|
||||||
focus={true}
|
focus={true}
|
||||||
>
|
>
|
||||||
{uploadAllButton}
|
{uploadAllButton}
|
Loading…
Reference in New Issue