2015-12-02 21:16:16 +03:00
|
|
|
/*
|
2021-03-05 23:06:53 +03:00
|
|
|
Copyright 2015, 2016, 2019, 2021 The Matrix.org Foundation C.I.C.
|
2015-12-02 21:16:16 +03:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2019-08-30 12:34:59 +03:00
|
|
|
import React from 'react';
|
2019-04-08 19:53:39 +03:00
|
|
|
import ContentMessages from '../../ContentMessages';
|
2020-05-14 05:41:41 +03:00
|
|
|
import dis from "../../dispatcher/dispatcher";
|
2019-12-21 00:41:07 +03:00
|
|
|
import filesize from "filesize";
|
2017-06-07 13:40:46 +03:00
|
|
|
import { _t } from '../../languageHandler';
|
2021-03-05 23:06:53 +03:00
|
|
|
import {Room} from "matrix-js-sdk/src/models/room";
|
2021-03-05 23:20:50 +03:00
|
|
|
import {ActionPayload} from "../../dispatcher/payloads";
|
|
|
|
import {Action} from "../../dispatcher/actions";
|
2021-03-06 00:14:43 +03:00
|
|
|
import ProgressBar from "../views/elements/ProgressBar";
|
2015-12-02 21:16:16 +03:00
|
|
|
|
2021-03-05 23:06:53 +03:00
|
|
|
interface IProps {
|
|
|
|
room: Room;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IState {
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class UploadBar extends React.Component<IProps, IState> {
|
|
|
|
private dispatcherRef: string;
|
|
|
|
private mounted: boolean;
|
2015-12-02 21:16:16 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
componentDidMount() {
|
2017-03-16 17:19:17 +03:00
|
|
|
this.dispatcherRef = dis.register(this.onAction);
|
2015-12-02 21:16:16 +03:00
|
|
|
this.mounted = true;
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2015-12-02 21:16:16 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
componentWillUnmount() {
|
2015-12-02 21:16:16 +03:00
|
|
|
this.mounted = false;
|
2017-03-16 17:19:17 +03:00
|
|
|
dis.unregister(this.dispatcherRef);
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2015-12-02 21:16:16 +03:00
|
|
|
|
2021-03-05 23:20:50 +03:00
|
|
|
private onAction = (payload: ActionPayload) => {
|
2015-12-02 21:16:16 +03:00
|
|
|
switch (payload.action) {
|
2021-03-05 23:20:50 +03:00
|
|
|
case Action.UploadProgress:
|
|
|
|
case Action.UploadFinished:
|
|
|
|
case Action.UploadCanceled:
|
|
|
|
case Action.UploadFailed:
|
2015-12-02 21:16:16 +03:00
|
|
|
if (this.mounted) this.forceUpdate();
|
|
|
|
break;
|
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2015-12-02 21:16:16 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
render() {
|
2019-04-01 18:42:41 +03:00
|
|
|
const uploads = ContentMessages.sharedInstance().getCurrentUploads();
|
2016-04-14 21:11:20 +03:00
|
|
|
|
|
|
|
// for testing UI... - also fix up the ContentMessages.getCurrentUploads().length
|
|
|
|
// check in RoomView
|
|
|
|
//
|
|
|
|
// uploads = [{
|
|
|
|
// roomId: this.props.room.roomId,
|
|
|
|
// loaded: 123493,
|
|
|
|
// total: 347534,
|
|
|
|
// fileName: "testing_fooble.jpg",
|
|
|
|
// }];
|
|
|
|
|
2021-03-06 00:14:43 +03:00
|
|
|
const uploadsHere = uploads.filter(u => u.roomId === this.props.room.roomId);
|
|
|
|
if (uploadsHere.length == 0) {
|
|
|
|
return null;
|
2015-12-02 21:16:16 +03:00
|
|
|
}
|
|
|
|
|
2021-03-06 00:14:43 +03:00
|
|
|
const currentUpload = uploadsHere[0];
|
|
|
|
const uploadSize = filesize(currentUpload.total);
|
2015-12-02 21:16:16 +03:00
|
|
|
|
2017-06-07 13:40:46 +03:00
|
|
|
// MUST use var name 'count' for pluralization to kick in
|
2020-10-30 21:18:17 +03:00
|
|
|
const uploadText = _t(
|
2021-03-06 00:14:43 +03:00
|
|
|
"Uploading %(filename)s and %(count)s others", {
|
|
|
|
filename: currentUpload.fileName,
|
|
|
|
count: uploadsHere.length - 1,
|
|
|
|
},
|
2020-10-30 21:18:17 +03:00
|
|
|
);
|
2015-12-02 21:16:16 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="mx_UploadBar">
|
2019-01-11 04:37:28 +03:00
|
|
|
<img className="mx_UploadBar_uploadCancel mx_filterFlipColor" src={require("../../../res/img/cancel.svg")} width="18" height="18"
|
2021-03-06 00:14:43 +03:00
|
|
|
onClick={function() { ContentMessages.sharedInstance().cancelUpload(currentUpload.promise); }}
|
2015-12-02 21:16:16 +03:00
|
|
|
/>
|
2021-03-06 00:14:43 +03:00
|
|
|
<div className="mx_UploadBar_uploadFilename">{uploadText} ({uploadSize})</div>
|
|
|
|
<ProgressBar value={currentUpload.loaded} max={currentUpload.total} />
|
2015-12-02 21:16:16 +03:00
|
|
|
</div>
|
|
|
|
);
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
|
|
|
}
|