Skip to content

Commit 29b4f59

Browse files
committed
Basically working upload progress bar.
1 parent a477c8b commit 29b4f59

4 files changed

Lines changed: 66 additions & 21 deletions

File tree

‎skins/base/css/organisms/RoomView.css‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,14 @@ limitations under the License.
117117
flex: 0 0 63px;
118118
margin-right: 2px;
119119
}
120+
121+
.mx_RoomView_uploadProgressOuter {
122+
width: 100%;
123+
background-color: black;
124+
height: 5px;
125+
}
126+
127+
.mx_RoomView_uploadProgressInner {
128+
background-color: blue;
129+
height: 5px;
130+
}

‎skins/base/views/molecules/MessageComposer.js‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,8 @@ module.exports = React.createClass({
3232

3333
onUploadFileSelected: function(ev) {
3434
var files = ev.target.files;
35-
36-
ContentMessages.sendContentToRoom(
37-
files[0], this.props.room.roomId, MatrixClientPeg.get()
38-
).progress(function(ev) {
39-
//console.log("Upload: "+ev.loaded+" / "+ev.total);
40-
}).done(undefined, function() {
41-
// display error message
42-
});
35+
// MessageComposer shouldn't have to rely on it's parent passing in a callback to upload a file
36+
this.props.uploadFile(files[0]);
4337
},
4438

4539
render: function() {

‎skins/base/views/organisms/RoomView.js‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var MatrixClientPeg = require("../../../../src/MatrixClientPeg");
2222

2323
var ComponentBroker = require('../../../../src/ComponentBroker');
2424
var classNames = require("classnames");
25+
var filesize = require('filesize');
2526

2627
var MessageTile = ComponentBroker.get('molecules/MessageTile');
2728
var RoomHeader = ComponentBroker.get('molecules/RoomHeader');
@@ -76,13 +77,30 @@ module.exports = React.createClass({
7677
<div />
7778
);
7879

79-
var typingString = this.getWhoIsTypingString();
80-
if (typingString) {
80+
if (this.state.upload) {
81+
var innerProgressStyle = {
82+
width: ((this.state.upload.uploadedBytes / this.state.upload.totalBytes) * 100) + '%'
83+
};
8184
statusBar = (
82-
<div className="mx_RoomView_typingBar">
83-
{typingString}
85+
<div className="mx_RoomView_uploadBar">
86+
<span className="mx_RoomView_uploadFilename">Uploading {this.state.upload.fileName}</span>
87+
<span className="mx_RoomView_uploadBytes">
88+
{filesize(this.state.upload.uploadedBytes)} / {filesize(this.state.upload.totalBytes)}
89+
</span>
90+
<div className="mx_RoomView_uploadProgressOuter">
91+
<div className="mx_RoomView_uploadProgressInner" style={innerProgressStyle}></div>
92+
</div>
8493
</div>
8594
);
95+
} else {
96+
var typingString = this.getWhoIsTypingString();
97+
if (typingString) {
98+
statusBar = (
99+
<div className="mx_RoomView_typingBar">
100+
{typingString}
101+
</div>
102+
);
103+
}
86104
}
87105

88106
return (
@@ -105,7 +123,7 @@ module.exports = React.createClass({
105123
{statusBar}
106124
</div>
107125
</div>
108-
<MessageComposer room={this.state.room} />
126+
<MessageComposer room={this.state.room} uploadFile={this.uploadFile} />
109127
</div>
110128
);
111129
}

‎src/controllers/organisms/RoomView.js‎

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,18 +231,40 @@ module.exports = {
231231
ev.stopPropagation();
232232
ev.preventDefault();
233233
var files = ev.dataTransfer.files;
234-
235234
if (files.length == 1) {
236-
ContentMessages.sendContentToRoom(
237-
files[0], this.props.roomId, MatrixClientPeg.get()
238-
).progress(function(ev) {
239-
//console.log("Upload: "+ev.loaded+" / "+ev.total);
240-
}).done(undefined, function() {
241-
// display error message
242-
});
235+
this.uploadFile(files[0]);
243236
}
244237
},
245238

239+
uploadFile: function(file) {
240+
this.setState({
241+
upload: {
242+
fileName: file.name,
243+
uploadedBytes: 0,
244+
totalBytes: file.size
245+
}
246+
});
247+
var self = this;
248+
ContentMessages.sendContentToRoom(
249+
file, this.props.roomId, MatrixClientPeg.get()
250+
).progress(function(ev) {
251+
//console.log("Upload: "+ev.loaded+" / "+ev.total);
252+
self.setState({
253+
upload: {
254+
fileName: file.name,
255+
uploadedBytes: ev.loaded,
256+
totalBytes: ev.total
257+
}
258+
});
259+
}).finally(function() {
260+
self.setState({
261+
upload: undefined
262+
});
263+
}).done(undefined, function() {
264+
// display error message
265+
});
266+
},
267+
246268
getWhoIsTypingString: function() {
247269
return WhoIsTyping.whoIsTypingString(this.state.room);
248270
},

0 commit comments

Comments
 (0)