diff --git a/app/assets/javascripts/discourse/components/composer-editor.js.es6 b/app/assets/javascripts/discourse/components/composer-editor.js.es6 index 02d59d09c..9d8ddaf56 100644 --- a/app/assets/javascripts/discourse/components/composer-editor.js.es6 +++ b/app/assets/javascripts/discourse/components/composer-editor.js.es6 @@ -117,9 +117,14 @@ export default Ember.Component.extend({ }); }, - _resetUpload() { - this.setProperties({ uploadProgress: 0, isUploading: false }); - this.set('composer.reply', this.get('composer.reply').replace(this.get('uploadPlaceholder'), "")); + _resetUpload(removePlaceholder) { + this._validUploads--; + if (this._validUploads === 0) { + this.setProperties({ uploadProgress: 0, isUploading: false, isCancellable: false }); + } + if (removePlaceholder) { + this.set('composer.reply', this.get('composer.reply').replace(this.get('uploadPlaceholder'), "")); + } }, _bindUploadTarget() { @@ -147,16 +152,19 @@ export default Ember.Component.extend({ }); $element.on("fileuploadsend", (e, data) => { - // add upload placeholder - this.appEvents.trigger('composer:insert-text', uploadPlaceholder); + this._validUploads++; + // add upload placeholders (as much placeholders as valid files dropped) + const placeholder = _.times(this._validUploads, () => uploadPlaceholder).join("\n"); + this.appEvents.trigger('composer:insert-text', placeholder); - if (data.xhr) { + if (data.xhr && data.originalFiles.length === 1) { + this.set("isCancellable", true); this._xhr = data.xhr(); } }); $element.on("fileuploadfail", (e, data) => { - this._resetUpload(); + this._resetUpload(true); const userCancelled = this._xhr && this._xhr._userCancelled; this._xhr = null; @@ -172,13 +180,14 @@ export default Ember.Component.extend({ if (!this._xhr || !this._xhr._userCancelled) { const markdown = Discourse.Utilities.getUploadMarkdown(upload); this.set('composer.reply', this.get('composer.reply').replace(uploadPlaceholder, markdown)); + this._resetUpload(false); + } else { + this._resetUpload(true); } } else { + this._resetUpload(true); Discourse.Utilities.displayErrorForUpload(upload); } - - // reset upload state - this._resetUpload(); }); if (Discourse.Mobile.mobileView) { @@ -276,6 +285,7 @@ export default Ember.Component.extend({ @on('willDestroyElement') _unbindUploadTarget() { + this._validUploads = 0; this.$(".mobile-file-upload").off("click.uploader"); this.messageBus.unsubscribe("/uploads/composer"); const $uploadTarget = this.$(); @@ -302,9 +312,8 @@ export default Ember.Component.extend({ if (this._xhr) { this._xhr._userCancelled = true; this._xhr.abort(); - this._resetUpload(); } - this._resetUpload(); + this._resetUpload(true); }, showOptions() { diff --git a/app/assets/javascripts/discourse/templates/components/composer-editor.hbs b/app/assets/javascripts/discourse/templates/components/composer-editor.hbs index 23acc3df1..cd89f1ae8 100644 --- a/app/assets/javascripts/discourse/templates/components/composer-editor.hbs +++ b/app/assets/javascripts/discourse/templates/components/composer-editor.hbs @@ -21,7 +21,9 @@
{{loading-spinner size="small"}} {{i18n 'upload_selector.uploading'}} {{uploadProgress}}% - {{fa-icon "times"}} + {{#if isCancellable}} + {{fa-icon "times"}} + {{/if}}
{{/if}}