diff --git a/js/app.js b/js/app.js index 9cdfb089..11e0674b 100644 --- a/js/app.js +++ b/js/app.js @@ -283,6 +283,7 @@ class Application { this.modalCommentLimit = 40; this.modalCommentLoadPromise = null; this.modalCommentPublishPromise = null; + this.uploadSubmitPromise = null; this.pendingModeratedPlayback = null; this.lastIdentityRefreshPromise = null; this.profileIdentityController = new ProfileIdentityController({ @@ -4639,31 +4640,57 @@ class Application { * Actually handle the upload form submission. */ async handleUploadSubmitEvent(event) { + if (this.uploadSubmitPromise) { + devLogger.warn( + "[Application] Ignoring upload submit while a publish is already in progress.", + ); + this.showStatus( + "Please wait for your current video to finish publishing before sharing another.", + { autoHideMs: 6000, showSpinner: false }, + ); + if (this.uploadModal?.updateCustomSubmitButtonState) { + this.uploadModal.updateCustomSubmitButtonState(); + } + return; + } + const payload = event?.detail?.payload || {}; + const submitPromise = (async () => { + try { + const publishResult = await this.authService.handleUploadSubmit(payload, { + publish: (data) => + this.publishVideoNote(data, { + onSuccess: () => { + if (this.uploadModal?.resetCustomForm) { + this.uploadModal.resetCustomForm(); + } + }, + }), + }); + if (!publishResult && this.uploadModal?.cancelCustomSubmitCooldown) { + this.uploadModal.cancelCustomSubmitCooldown(); + } + } catch (error) { + if (this.uploadModal?.cancelCustomSubmitCooldown) { + this.uploadModal.cancelCustomSubmitCooldown(); + } + const message = this.describeLoginError( + error, + "Login required to publish videos.", + ); + this.showError(message); + } + })(); + + this.uploadSubmitPromise = submitPromise; + try { - const publishResult = await this.authService.handleUploadSubmit(payload, { - publish: (data) => - this.publishVideoNote(data, { - onSuccess: () => { - if (this.uploadModal?.resetCustomForm) { - this.uploadModal.resetCustomForm(); - } - }, - }), - }); - if (!publishResult && this.uploadModal?.cancelCustomSubmitCooldown) { - this.uploadModal.cancelCustomSubmitCooldown(); + await submitPromise; + } finally { + if (this.uploadSubmitPromise === submitPromise) { + this.uploadSubmitPromise = null; } - } catch (error) { - if (this.uploadModal?.cancelCustomSubmitCooldown) { - this.uploadModal.cancelCustomSubmitCooldown(); - } - const message = this.describeLoginError( - error, - "Login required to publish videos.", - ); - this.showError(message); } } diff --git a/js/ui/components/UploadModal.js b/js/ui/components/UploadModal.js index 65350aca..544bb25f 100644 --- a/js/ui/components/UploadModal.js +++ b/js/ui/components/UploadModal.js @@ -397,7 +397,6 @@ export class UploadModal { this.updateCustomSubmitButtonState(); return; } - this.startCustomSubmitCooldown(); this.handleCustomSubmit(); }); } @@ -758,6 +757,7 @@ export class UploadModal { return; } + this.startCustomSubmitCooldown(); this.emit("upload:submit", { payload }); }