2015-12-02 18:16:16 +00:00
|
|
|
/*
|
2016-01-07 04:06:39 +00:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2015-12-02 18:16:16 +00: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.
|
|
|
|
*/
|
|
|
|
|
2017-10-11 16:56:17 +00:00
|
|
|
const React = require('react');
|
2017-12-26 01:03:18 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2017-10-11 16:56:17 +00:00
|
|
|
const ContentMessages = require('../../ContentMessages');
|
|
|
|
const dis = require('../../dispatcher');
|
|
|
|
const filesize = require('filesize');
|
2017-06-07 10:40:46 +00:00
|
|
|
import { _t } from '../../languageHandler';
|
2015-12-02 18:16:16 +00:00
|
|
|
|
|
|
|
module.exports = React.createClass({displayName: 'UploadBar',
|
|
|
|
propTypes: {
|
2017-12-26 01:03:18 +00:00
|
|
|
room: PropTypes.object,
|
2015-12-02 18:16:16 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount: function() {
|
2017-03-16 14:19:17 +00:00
|
|
|
this.dispatcherRef = dis.register(this.onAction);
|
2015-12-02 18:16:16 +00:00
|
|
|
this.mounted = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
|
|
|
this.mounted = false;
|
2017-03-16 14:19:17 +00:00
|
|
|
dis.unregister(this.dispatcherRef);
|
2015-12-02 18:16:16 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onAction: function(payload) {
|
|
|
|
switch (payload.action) {
|
|
|
|
case 'upload_progress':
|
|
|
|
case 'upload_finished':
|
|
|
|
case 'upload_failed':
|
|
|
|
if (this.mounted) this.forceUpdate();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2017-10-11 16:56:17 +00:00
|
|
|
const uploads = ContentMessages.getCurrentUploads();
|
2016-04-14 18:11:20 +00: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",
|
|
|
|
// }];
|
|
|
|
|
2015-12-02 18:16:16 +00:00
|
|
|
if (uploads.length == 0) {
|
2017-01-20 14:22:27 +00:00
|
|
|
return <div />;
|
2015-12-02 18:16:16 +00:00
|
|
|
}
|
|
|
|
|
2017-10-11 16:56:17 +00:00
|
|
|
let upload;
|
|
|
|
for (let i = 0; i < uploads.length; ++i) {
|
2015-12-02 18:16:16 +00:00
|
|
|
if (uploads[i].roomId == this.props.room.roomId) {
|
|
|
|
upload = uploads[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!upload) {
|
2017-01-20 14:22:27 +00:00
|
|
|
return <div />;
|
2015-12-02 18:16:16 +00:00
|
|
|
}
|
|
|
|
|
2017-10-11 16:56:17 +00:00
|
|
|
const innerProgressStyle = {
|
|
|
|
width: ((upload.loaded / (upload.total || 1)) * 100) + '%',
|
2015-12-02 18:16:16 +00:00
|
|
|
};
|
2017-10-11 16:56:17 +00:00
|
|
|
let uploadedSize = filesize(upload.loaded);
|
|
|
|
const totalSize = filesize(upload.total);
|
2017-01-20 14:22:27 +00:00
|
|
|
if (uploadedSize.replace(/^.* /, '') === totalSize.replace(/^.* /, '')) {
|
2015-12-02 18:16:16 +00:00
|
|
|
uploadedSize = uploadedSize.replace(/ .*/, '');
|
|
|
|
}
|
|
|
|
|
2017-06-07 10:40:46 +00:00
|
|
|
// MUST use var name 'count' for pluralization to kick in
|
2017-10-11 16:56:17 +00:00
|
|
|
const uploadText = _t("Uploading %(filename)s and %(count)s others", {filename: upload.fileName, count: (uploads.length - 1)});
|
2015-12-02 18:16:16 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="mx_UploadBar">
|
|
|
|
<div className="mx_UploadBar_uploadProgressOuter">
|
|
|
|
<div className="mx_UploadBar_uploadProgressInner" style={innerProgressStyle}></div>
|
|
|
|
</div>
|
2019-01-11 01:37:28 +00:00
|
|
|
<img className="mx_UploadBar_uploadIcon mx_filterFlipColor" src={require("../../../res/img/fileicon.png")} width="17" height="22" />
|
|
|
|
<img className="mx_UploadBar_uploadCancel mx_filterFlipColor" src={require("../../../res/img/cancel.svg")} width="18" height="18"
|
2015-12-02 18:16:16 +00:00
|
|
|
onClick={function() { ContentMessages.cancelUpload(upload.promise); }}
|
|
|
|
/>
|
|
|
|
<div className="mx_UploadBar_uploadBytes">
|
|
|
|
{ uploadedSize } / { totalSize }
|
|
|
|
</div>
|
2017-10-11 16:56:17 +00:00
|
|
|
<div className="mx_UploadBar_uploadFilename">{ uploadText }</div>
|
2015-12-02 18:16:16 +00:00
|
|
|
</div>
|
|
|
|
);
|
2017-10-11 16:56:17 +00:00
|
|
|
},
|
2015-12-02 18:16:16 +00:00
|
|
|
});
|