diff --git a/app/assets/javascripts/wizard/components/styling-preview.js b/app/assets/javascripts/wizard/components/styling-preview.js index a45d1ef168e..184931bd2d2 100644 --- a/app/assets/javascripts/wizard/components/styling-preview.js +++ b/app/assets/javascripts/wizard/components/styling-preview.js @@ -4,7 +4,7 @@ import { darkLightDiff, } from "wizard/lib/preview"; import I18n from "I18n"; -import { observes } from "discourse-common/utils/decorators"; +import { bind, observes } from "discourse-common/utils/decorators"; const LOREM = ` Lorem ipsum dolor sit amet, consectetur adipiscing. @@ -20,6 +20,16 @@ export default createPreviewComponent(659, 320, { startX: 0, scrollLeft: 0, + init() { + this._super(...arguments); + this.wizard.on("homepageStyleChanged", this.onHomepageStyleChange); + }, + + willDestroy() { + this._super(...arguments); + this.wizard.off("homepageStyleChanged", this.onHomepageStyleChange); + }, + mouseDown(e) { const slider = this.element.querySelector(".previews"); this.setProperties({ @@ -61,10 +71,11 @@ export default createPreviewComponent(659, 320, { this._super(...arguments); this.triggerRepaint(); + }, - if (this.stylingDropdown?.id === "homepage_style") { - this.set("previewTopic", false); - } + @bind + onHomepageStyleChange() { + this.set("previewTopic", false); }, @observes("previewTopic") diff --git a/app/assets/javascripts/wizard/components/wizard-field-dropdown.js b/app/assets/javascripts/wizard/components/wizard-field-dropdown.js index f0c510ba34a..5ac860fdc3c 100644 --- a/app/assets/javascripts/wizard/components/wizard-field-dropdown.js +++ b/app/assets/javascripts/wizard/components/wizard-field-dropdown.js @@ -30,7 +30,10 @@ export default Component.extend({ actions: { onChangeValue(value) { this.set("field.value", value); - this.stylingDropdownChanged(this.field.id, value); + + if (this.field.id === "homepage_style") { + this.wizard.trigger("homepageStyleChanged"); + } }, }, }); diff --git a/app/assets/javascripts/wizard/components/wizard-step.js b/app/assets/javascripts/wizard/components/wizard-step.js index 0dc304e860a..ea0c591630b 100644 --- a/app/assets/javascripts/wizard/components/wizard-step.js +++ b/app/assets/javascripts/wizard/components/wizard-step.js @@ -11,11 +11,6 @@ export default Component.extend({ classNames: ["wizard-step"], saving: null, - init() { - this._super(...arguments); - this.set("stylingDropdown", {}); - }, - didInsertElement() { this._super(...arguments); this.autoFocus(); @@ -117,10 +112,6 @@ export default Component.extend({ document.location = getUrl("/"); }, - stylingDropdownChanged(id, value) { - this.set("stylingDropdown", { id, value }); - }, - exitEarly() { const step = this.step; step.validate(); diff --git a/app/assets/javascripts/wizard/models/wizard.js b/app/assets/javascripts/wizard/models/wizard.js index f6b83ede7bd..37af97a47cd 100644 --- a/app/assets/javascripts/wizard/models/wizard.js +++ b/app/assets/javascripts/wizard/models/wizard.js @@ -1,10 +1,11 @@ import EmberObject from "@ember/object"; +import Evented from "@ember/object/evented"; import Step from "wizard/models/step"; import WizardField from "wizard/models/wizard-field"; import { ajax } from "wizard/lib/ajax"; import discourseComputed from "discourse-common/utils/decorators"; -const Wizard = EmberObject.extend({ +const Wizard = EmberObject.extend(Evented, { @discourseComputed("steps.length") totalSteps: (length) => length, diff --git a/app/assets/javascripts/wizard/templates/components/styling-preview.hbs b/app/assets/javascripts/wizard/templates/components/styling-preview.hbs index 9dde43e5d1b..08a83fcce83 100644 --- a/app/assets/javascripts/wizard/templates/components/styling-preview.hbs +++ b/app/assets/javascripts/wizard/templates/components/styling-preview.hbs @@ -7,7 +7,6 @@ {{homepage-preview wizard=wizard step=step - stylingDropdown=stylingDropdown }} diff --git a/app/assets/javascripts/wizard/templates/components/wizard-field.hbs b/app/assets/javascripts/wizard/templates/components/wizard-field.hbs index d1d9fce684c..5a5576c834b 100644 --- a/app/assets/javascripts/wizard/templates/components/wizard-field.hbs +++ b/app/assets/javascripts/wizard/templates/components/wizard-field.hbs @@ -15,11 +15,10 @@