diff --git a/app/assets/javascripts/discourse/app/components/pick-files-button.hbs b/app/assets/javascripts/discourse/app/components/pick-files-button.hbs index f75ecc5a78d..f35485a4448 100644 --- a/app/assets/javascripts/discourse/app/components/pick-files-button.hbs +++ b/app/assets/javascripts/discourse/app/components/pick-files-button.hbs @@ -7,6 +7,7 @@ {{/if}} {{#if this.acceptsAllFormats}} {{else}} { @@ -359,7 +361,7 @@ export default class UppyUpload { ); this.appEvents.on( `upload-mixin:${this.config.id}:cancel-upload`, - this._cancelSingleUpload + this.cancelSingleUpload ); this.config.uppyReady?.(); @@ -372,6 +374,11 @@ export default class UppyUpload { }); } + @bind + openPicker() { + this._fileInputEl.click(); + } + #triggerInProgressUploadsEvent() { this.config.onProgressUploadsChanged?.(this.inProgressUploads); this.appEvents.trigger( @@ -469,11 +476,18 @@ export default class UppyUpload { } @bind - _cancelSingleUpload(data) { + cancelSingleUpload(data) { this.uppyWrapper.uppyInstance.removeFile(data.fileId); this.#removeInProgressUpload(data.fileId); } + @bind + cancelAllUploads() { + this.uppyWrapper.uppyInstance?.cancelAll(); + this.inProgressUploads.length = 0; + this.#triggerInProgressUploadsEvent(); + } + @bind async addFiles(files, opts = {}) { if (!this.session.csrfToken) { @@ -506,11 +520,19 @@ export default class UppyUpload { type: "POST", data: deepMerge( { unique_identifier: file.meta.uniqueUploadIdentifier }, - this.config.additionalParams + this.#resolvedAdditionalParams ), }); } + get #resolvedAdditionalParams() { + if (typeof this.config.additionalParams === "function") { + return this.config.additionalParams(); + } else { + return this.config.additionalParams; + } + } + #reset() { this.uppyWrapper.uppyInstance?.cancelAll(); Object.assign(this, { @@ -524,10 +546,6 @@ export default class UppyUpload { } #removeInProgressUpload(fileId) { - if (this.isDestroyed || this.isDestroying) { - return; - } - const index = this.inProgressUploads.findIndex((upl) => upl.id === fileId); if (index === -1) { return; diff --git a/app/assets/javascripts/discourse/app/mixins/uppy-upload.js b/app/assets/javascripts/discourse/app/mixins/uppy-upload.js index 681c1349964..764af5b4c29 100644 --- a/app/assets/javascripts/discourse/app/mixins/uppy-upload.js +++ b/app/assets/javascripts/discourse/app/mixins/uppy-upload.js @@ -74,7 +74,7 @@ export default Mixin.create({ function configShim(component) { return { get autoStartUploads() { - return component.autoStartUploads || true; + return component.autoStartUploads ?? true; }, get id() { return component.id;