From fa92f8bc94deb5969caf6af6943b0cb3c6725fe5 Mon Sep 17 00:00:00 2001 From: Penar Musaraj Date: Thu, 28 Mar 2024 15:03:40 -0400 Subject: [PATCH] DEV: Add `{{hide-application-sidebar}}` helper (#26310) --- .../discourse/app/controllers/application.js | 30 ++++++++----------- .../app/helpers/hide-application-sidebar.js | 18 +++++++++++ .../discourse/app/mixins/disable-sidebar.js | 6 ++++ .../discourse/app/routes/invites-show.js | 3 +- .../app/routes/second-factor-auth.js | 3 +- .../discourse/app/routes/wizard.js | 3 +- .../discourse/app/services/sidebar-state.js | 15 ++++++++++ .../discourse/app/templates/invites/show.hbs | 1 + .../app/templates/second-factor-auth.hbs | 2 ++ .../discourse/app/templates/wizard.gjs | 2 ++ 10 files changed, 59 insertions(+), 24 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/helpers/hide-application-sidebar.js diff --git a/app/assets/javascripts/discourse/app/controllers/application.js b/app/assets/javascripts/discourse/app/controllers/application.js index 0a9b0e901dd..32b7368ae84 100644 --- a/app/assets/javascripts/discourse/app/controllers/application.js +++ b/app/assets/javascripts/discourse/app/controllers/application.js @@ -13,9 +13,10 @@ export default Controller.extend({ showTop: true, router: service(), footer: service(), + sidebarState: service(), showSidebar: false, - navigationMenuQueryParamOverride: null, sidebarDisabledRouteOverride: false, + navigationMenuQueryParamOverride: null, showSiteHeader: true, init() { @@ -67,31 +68,24 @@ export default Controller.extend({ document.body.classList.remove("sidebar-animate"); }, - @discourseComputed( - "navigationMenuQueryParamOverride", - "siteSettings.navigation_menu", - "canDisplaySidebar", - "sidebarDisabledRouteOverride" - ) - sidebarEnabled( - navigationMenuQueryParamOverride, - navigationMenu, - canDisplaySidebar, - sidebarDisabledRouteOverride - ) { - if (!canDisplaySidebar) { + get sidebarEnabled() { + if (!this.canDisplaySidebar) { return false; } - if (sidebarDisabledRouteOverride) { + if (this.sidebarState.sidebarHidden) { return false; } - if (navigationMenuQueryParamOverride === "sidebar") { + if (this.sidebarDisabledRouteOverride) { + return false; + } + + if (this.navigationMenuQueryParamOverride === "sidebar") { return true; } - if (navigationMenuQueryParamOverride === "header_dropdown") { + if (this.navigationMenuQueryParamOverride === "header_dropdown") { return false; } @@ -100,7 +94,7 @@ export default Controller.extend({ return false; } - return navigationMenu === "sidebar"; + return this.siteSettings.navigation_menu === "sidebar"; }, calculateShowSidebar() { diff --git a/app/assets/javascripts/discourse/app/helpers/hide-application-sidebar.js b/app/assets/javascripts/discourse/app/helpers/hide-application-sidebar.js new file mode 100644 index 00000000000..47fb84aacc2 --- /dev/null +++ b/app/assets/javascripts/discourse/app/helpers/hide-application-sidebar.js @@ -0,0 +1,18 @@ +import Helper from "@ember/component/helper"; +import { scheduleOnce } from "@ember/runloop"; +import { service } from "@ember/service"; + +export default class HideApplicationSidebar extends Helper { + @service sidebarState; + + constructor() { + super(...arguments); + scheduleOnce("afterRender", this, this.registerHider); + } + + registerHider() { + this.sidebarState.registerHider(this); + } + + compute() {} +} diff --git a/app/assets/javascripts/discourse/app/mixins/disable-sidebar.js b/app/assets/javascripts/discourse/app/mixins/disable-sidebar.js index e96c2618977..d6a91157394 100644 --- a/app/assets/javascripts/discourse/app/mixins/disable-sidebar.js +++ b/app/assets/javascripts/discourse/app/mixins/disable-sidebar.js @@ -1,7 +1,13 @@ import Mixin from "@ember/object/mixin"; +import deprecated from "discourse-common/lib/deprecated"; export default Mixin.create({ activate() { + deprecated( + "The DisableSidebar mixin is deprecated. Instead, please add the {{hide-application-sidebar}} helper to an Ember template.", + { id: "discourse.hide-application-sidebar" } + ); + this.controllerFor("application").setProperties({ sidebarDisabledRouteOverride: true, }); diff --git a/app/assets/javascripts/discourse/app/routes/invites-show.js b/app/assets/javascripts/discourse/app/routes/invites-show.js index 5c87df78afb..6e9dc672396 100644 --- a/app/assets/javascripts/discourse/app/routes/invites-show.js +++ b/app/assets/javascripts/discourse/app/routes/invites-show.js @@ -1,10 +1,9 @@ import PreloadStore from "discourse/lib/preload-store"; -import DisableSidebar from "discourse/mixins/disable-sidebar"; import DiscourseRoute from "discourse/routes/discourse"; import { deepMerge } from "discourse-common/lib/object"; import I18n from "discourse-i18n"; -export default DiscourseRoute.extend(DisableSidebar, { +export default DiscourseRoute.extend({ titleToken() { return I18n.t("invites.accept_title"); }, diff --git a/app/assets/javascripts/discourse/app/routes/second-factor-auth.js b/app/assets/javascripts/discourse/app/routes/second-factor-auth.js index 15310c71550..986545c80f0 100644 --- a/app/assets/javascripts/discourse/app/routes/second-factor-auth.js +++ b/app/assets/javascripts/discourse/app/routes/second-factor-auth.js @@ -1,10 +1,9 @@ import { ajax } from "discourse/lib/ajax"; import { extractError } from "discourse/lib/ajax-error"; import PreloadStore from "discourse/lib/preload-store"; -import DisableSidebar from "discourse/mixins/disable-sidebar"; import DiscourseRoute from "discourse/routes/discourse"; -export default DiscourseRoute.extend(DisableSidebar, { +export default DiscourseRoute.extend({ queryParams: { nonce: { refreshModel: true }, }, diff --git a/app/assets/javascripts/discourse/app/routes/wizard.js b/app/assets/javascripts/discourse/app/routes/wizard.js index f32f0409a34..c0cb4821dab 100644 --- a/app/assets/javascripts/discourse/app/routes/wizard.js +++ b/app/assets/javascripts/discourse/app/routes/wizard.js @@ -1,8 +1,7 @@ import Route from "@ember/routing/route"; -import DisableSidebar from "discourse/mixins/disable-sidebar"; import Wizard from "discourse/static/wizard/models/wizard"; -export default class WizardRoute extends Route.extend(DisableSidebar) { +export default class WizardRoute extends Route { model() { return Wizard.load(); } diff --git a/app/assets/javascripts/discourse/app/services/sidebar-state.js b/app/assets/javascripts/discourse/app/services/sidebar-state.js index 6194c233870..8127435b29b 100644 --- a/app/assets/javascripts/discourse/app/services/sidebar-state.js +++ b/app/assets/javascripts/discourse/app/services/sidebar-state.js @@ -1,6 +1,8 @@ import { tracked } from "@glimmer/tracking"; import { A } from "@ember/array"; +import { registerDestructor } from "@ember/destroyable"; import Service, { service } from "@ember/service"; +import { TrackedSet } from "@ember-compat/tracked-built-ins"; import { disableImplicitInjections } from "discourse/lib/implicit-injections"; import { currentPanelKey, @@ -23,12 +25,25 @@ export default class SidebarState extends Service { @tracked collapsedSections = A([]); previousState = {}; + #hiders = new TrackedSet(); constructor() { super(...arguments); this.#reset(); } + get sidebarHidden() { + return this.#hiders.size > 0; + } + + registerHider(ref) { + this.#hiders.add(ref); + + registerDestructor(ref, () => { + this.#hiders.delete(ref); + }); + } + setPanel(name) { if (this.currentPanelKey) { this.setPreviousState(); diff --git a/app/assets/javascripts/discourse/app/templates/invites/show.hbs b/app/assets/javascripts/discourse/app/templates/invites/show.hbs index 7a82860a416..9efc30e251a 100644 --- a/app/assets/javascripts/discourse/app/templates/invites/show.hbs +++ b/app/assets/javascripts/discourse/app/templates/invites/show.hbs @@ -1,4 +1,5 @@ {{body-class "invite-page"}} +{{hide-application-sidebar}}
diff --git a/app/assets/javascripts/discourse/app/templates/second-factor-auth.hbs b/app/assets/javascripts/discourse/app/templates/second-factor-auth.hbs index 3ce37f5a898..317a8cde9dc 100644 --- a/app/assets/javascripts/discourse/app/templates/second-factor-auth.hbs +++ b/app/assets/javascripts/discourse/app/templates/second-factor-auth.hbs @@ -1,3 +1,5 @@ +{{hide-application-sidebar}} + {{#if this.message}}
{{this.message}}
{{/if}} diff --git a/app/assets/javascripts/discourse/app/templates/wizard.gjs b/app/assets/javascripts/discourse/app/templates/wizard.gjs index 80dc4d944f4..6eb3ca18b0d 100644 --- a/app/assets/javascripts/discourse/app/templates/wizard.gjs +++ b/app/assets/javascripts/discourse/app/templates/wizard.gjs @@ -1,8 +1,10 @@ import RouteTemplate from "ember-route-template"; import hideApplicationFooter from "discourse/helpers/hide-application-footer"; +import hideApplicationSidebar from "discourse/helpers/hide-application-sidebar"; import DiscourseLogo from "discourse/static/wizard/components/discourse-logo"; export default RouteTemplate(