FIX: Make bindMobileUploadButton explicit for upload mixins (#14220)

FIX: Make bindMobileUploadButton explicit for upload mixins (#14220)

When using ComposerUpload and/or ComposerUploadUppy, we were always calling bindMobileUploadButton. However with more composer-like interfaces being developed, we need this to be optional, as not everywhere will have a separate mobile upload button to bind to.

Also makes it so the composer extending the ComposerUpload mixins is responsible for explicitly unbinding the mobile upload button if it needs to.

diff --git a/app/assets/javascripts/discourse/app/components/composer-editor.js b/app/assets/javascripts/discourse/app/components/composer-editor.js
index c319408..eb2d079 100644
--- a/app/assets/javascripts/discourse/app/components/composer-editor.js
+++ b/app/assets/javascripts/discourse/app/components/composer-editor.js
@@ -219,6 +219,8 @@ export default Component.extend(ComposerUpload, {
     }
 
     this._bindUploadTarget();
+    this._bindMobileUploadButton();
+
     this.appEvents.trigger("composer:will-open");
   },
 
@@ -607,6 +609,7 @@ export default Component.extend(ComposerUpload, {
 
   @on("willDestroyElement")
   _composerClosed() {
+    this._unbindMobileUploadButton();
     this.appEvents.trigger("composer:will-close");
     next(() => {
       // need to wait a bit for the "slide down" transition of the composer
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 885c86b..3636c05 100644
--- a/app/assets/javascripts/discourse/app/mixins/composer-upload-uppy.js
+++ b/app/assets/javascripts/discourse/app/mixins/composer-upload-uppy.js
@@ -46,11 +46,6 @@ export default Mixin.create({
 
   @on("willDestroyElement")
   _unbindUploadTarget() {
-    this.mobileUploadButton?.removeEventListener(
-      "click",
-      this.mobileUploadButtonEventListener
-    );
-
     this.fileInputEl?.removeEventListener(
       "change",
       this.fileInputEventListener
@@ -86,7 +81,6 @@ export default Mixin.create({
     this._unbindUploadTarget();
     this._bindFileInputChangeListener();
     this._bindPasteListener();
-    this._bindMobileUploadButton();
 
     this._uppyInstance = new Uppy({
       id: this.uppyId,
diff --git a/app/assets/javascripts/discourse/app/mixins/composer-upload.js b/app/assets/javascripts/discourse/app/mixins/composer-upload.js
index c3ada1c..01ab335 100644
--- a/app/assets/javascripts/discourse/app/mixins/composer-upload.js
+++ b/app/assets/javascripts/discourse/app/mixins/composer-upload.js
@@ -327,8 +327,6 @@ export default Mixin.create({
         }
       });
     });
-
-    this._bindMobileUploadButton();
   },
 
   _bindMobileUploadButton() {
@@ -345,13 +343,15 @@ export default Mixin.create({
     }
   },
 
-  @on("willDestroyElement")
-  _unbindUploadTarget() {
+  _unbindMobileUploadButton() {
     this.mobileUploadButton?.removeEventListener(
       "click",
       this.mobileUploadButtonEventListener
     );
+  },
 
+  @on("willDestroyElement")
+  _unbindUploadTarget() {
     this._validUploads = 0;
     const $uploadTarget = $(this.element);
     try {

GitHub sha: fa66d1fa82d6c768f265d3c3601110dca672a205

This commit appears in #14220 which was approved by tgxworld. It was merged by martin.