From 7eb7b7eba6ccb5acbd78ea9e0d11bac74de7e730 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 15 May 2024 13:46:56 +0200 Subject: [PATCH] Disable step controls when uploading --- .../custom-wizard-composer-editor.js.es6 | 5 +++- .../components/custom-wizard-step.js.es6 | 27 ++++++++++++++++++- .../components/custom-wizard-step.hbs | 4 +-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/assets/javascripts/discourse/components/custom-wizard-composer-editor.js.es6 b/assets/javascripts/discourse/components/custom-wizard-composer-editor.js.es6 index 95ae56c0..0f431f3d 100644 --- a/assets/javascripts/discourse/components/custom-wizard-composer-editor.js.es6 +++ b/assets/javascripts/discourse/components/custom-wizard-composer-editor.js.es6 @@ -18,6 +18,9 @@ import { inject as service } from "@ember/service"; const IMAGE_MARKDOWN_REGEX = /!\[(.*?)\|(\d{1,4}x\d{1,4})(,\s*\d{1,3}%)?(.*?)\]\((upload:\/\/.*?)\)(?!(.*`))/g; + +export const wizardComposerEdtiorEventPrefix = "wizard-editor"; + export default ComposerEditor.extend({ modal: service(), @@ -33,7 +36,7 @@ export default ComposerEditor.extend({ draftStatus: "null", replyPlaceholder: alias("field.translatedPlaceholder"), wizardEventFieldId: null, - composerEventPrefix: "wizard-editor", + composerEventPrefix: wizardComposerEdtiorEventPrefix, @on("didInsertElement") _composerEditorInit() { diff --git a/assets/javascripts/discourse/components/custom-wizard-step.js.es6 b/assets/javascripts/discourse/components/custom-wizard-step.js.es6 index 44bef872..99176259 100644 --- a/assets/javascripts/discourse/components/custom-wizard-step.js.es6 +++ b/assets/javascripts/discourse/components/custom-wizard-step.js.es6 @@ -7,8 +7,21 @@ import { cook } from "discourse/lib/text"; import CustomWizard, { updateCachedWizard, } from "discourse/plugins/discourse-custom-wizard/discourse/models/custom-wizard"; -import { alias, not } from "@ember/object/computed"; +import { alias, not, or } from "@ember/object/computed"; import discourseLater from "discourse-common/lib/later"; +import { wizardComposerEdtiorEventPrefix } from "./custom-wizard-composer-editor"; + +const uploadStartedEventKeys = [ + "upload-started" +]; +const uploadEndedEventKeys = [ + "upload-success", + "upload-error", + "upload-cancelled", + "uploads-cancelled", + "uploads-aborted", + "all-uploads-complete" +]; export default Component.extend({ classNameBindings: [":wizard-step", "step.id"], @@ -28,6 +41,17 @@ export default Component.extend({ cook(this.step.translatedDescription).then((cookedDescription) => { this.set("cookedDescription", cookedDescription); }); + + uploadStartedEventKeys.forEach(key => { + this.appEvents.on(`${wizardComposerEdtiorEventPrefix}:${key}`, () => { + this.set("uploading", true); + }); + }); + uploadEndedEventKeys.forEach(key => { + this.appEvents.on(`${wizardComposerEdtiorEventPrefix}:${key}`, () => { + this.set("uploading", false); + }); + }); }, didInsertElement() { @@ -40,6 +64,7 @@ export default Component.extend({ showNextButton: not("step.final"), showDoneButton: alias("step.final"), + btnsDisabled: or("saving", "uploading"), @discourseComputed( "step.index", diff --git a/assets/javascripts/discourse/templates/components/custom-wizard-step.hbs b/assets/javascripts/discourse/templates/components/custom-wizard-step.hbs index b9f0c06e..fd4e038e 100644 --- a/assets/javascripts/discourse/templates/components/custom-wizard-step.hbs +++ b/assets/javascripts/discourse/templates/components/custom-wizard-step.hbs @@ -60,7 +60,7 @@ type="button" class="wizard-btn next primary" {{action "nextStep"}} - disabled={{saving}} + disabled={{btnsDisabled}} tabindex={{primaryButtonIndex}} > {{i18n "wizard.next"}} @@ -73,7 +73,7 @@ type="button" class="wizard-btn done" {{action "done"}} - disabled={{saving}} + disabled={{btnsDisabled}} tabindex={{primaryButtonIndex}} > {{i18n "wizard.done_custom"}}