From 1cdb5b7e4a07da493d2d285bdc4987a3a4ff1139 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Mon, 20 Dec 2021 11:00:20 +1000 Subject: [PATCH] DEV: Add uppyReady hook to uppy mixins (#15361) This should be overridden in a child component if you need to hook into uppy events and be sure that everything is already set up for _uppyInstance. --- .../discourse/app/mixins/composer-upload-uppy.js | 6 ++++++ .../javascripts/discourse/app/mixins/uppy-upload.js | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/app/assets/javascripts/discourse/app/mixins/composer-upload-uppy.js b/app/assets/javascripts/discourse/app/mixins/composer-upload-uppy.js index 90bc04e681b..7ba98ad19ef 100644 --- a/app/assets/javascripts/discourse/app/mixins/composer-upload-uppy.js +++ b/app/assets/javascripts/discourse/app/mixins/composer-upload-uppy.js @@ -337,8 +337,14 @@ export default Mixin.create(ExtendableUploader, UppyS3Multipart, { this._setupUIPlugins(); this.uploadTargetBound = true; + this._uppyReady(); }, + // This should be overridden in a child component if you need to + // hook into uppy events and be sure that everything is already + // set up for _uppyInstance. + _uppyReady() {}, + @bind _handleUploadError(file, error, response) { this._removeInProgressUpload(file.id); diff --git a/app/assets/javascripts/discourse/app/mixins/uppy-upload.js b/app/assets/javascripts/discourse/app/mixins/uppy-upload.js index e37353001f1..8c5fcf1203b 100644 --- a/app/assets/javascripts/discourse/app/mixins/uppy-upload.js +++ b/app/assets/javascripts/discourse/app/mixins/uppy-upload.js @@ -224,8 +224,15 @@ export default Mixin.create(UppyS3Multipart, { this._useXHRUploads(); } } + + this._uppyReady(); }, + // This should be overridden in a child component if you need to + // hook into uppy events and be sure that everything is already + // set up for _uppyInstance. + _uppyReady() {}, + _startUpload() { if (!this.filesAwaitingUpload) { return; @@ -233,6 +240,7 @@ export default Mixin.create(UppyS3Multipart, { if (!this._uppyInstance?.getFiles().length) { return; } + this.set("uploading", true); return this._uppyInstance?.upload(); },