Added the ability to cancel file uploads on comments

Этот коммит содержится в:
hmhealey
2015-08-10 08:52:50 -04:00
родитель 4e8af44370
Коммит 4b74c873cc

Просмотреть файл

@@ -150,10 +150,18 @@ module.exports = React.createClass({
}, },
removePreview: function(filename) { removePreview: function(filename) {
var previews = this.state.previews; var previews = this.state.previews;
for (var i = 0; i < previews.length; i++) { var uploadsInProgress = this.state.uploadsInProgress;
if (previews[i] === filename) {
previews.splice(i, 1); // this can be either an uploaded file or an in progress upload that we need to remove
break; var index = previews.indexOf(filename);
if (index !== -1) {
previews.splice(index, 1);
} else {
index = uploadsInProgress.indexOf(filename);
if (index !== -1) {
uploadsInProgress.splice(index, 1);
this.refs.fileUpload.cancelUpload(filename);
} }
} }
@@ -162,9 +170,10 @@ module.exports = React.createClass({
draft = { message: '', uploadsInProgress: []}; draft = { message: '', uploadsInProgress: []};
} }
draft.previews = previews; draft.previews = previews;
draft.uploadsInProgress = uploadsInProgress;
PostStore.storeCommentDraft(this.props.rootId, draft); PostStore.storeCommentDraft(this.props.rootId, draft);
this.setState({previews: previews}); this.setState({previews: previews, uploadsInProgress: uploadsInProgress});
}, },
getInitialState: function() { getInitialState: function() {
PostStore.clearCommentDraftUploads(); PostStore.clearCommentDraftUploads();
@@ -225,6 +234,7 @@ module.exports = React.createClass({
id="reply_textbox" id="reply_textbox"
ref="textbox" /> ref="textbox" />
<FileUpload <FileUpload
ref='fileUpload'
getFileCount={this.getFileCount} getFileCount={this.getFileCount}
onUploadStart={this.handleUploadStart} onUploadStart={this.handleUploadStart}
onFileUpload={this.handleFileUploadComplete} onFileUpload={this.handleFileUploadComplete}