DEV: Add {{hide-application-sidebar}} helper (#26310)

This commit is contained in:
Penar Musaraj 2024-03-28 15:03:40 -04:00 committed by GitHub
parent e80593c23e
commit fa92f8bc94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 59 additions and 24 deletions

View File

@ -13,9 +13,10 @@ export default Controller.extend({
showTop: true, showTop: true,
router: service(), router: service(),
footer: service(), footer: service(),
sidebarState: service(),
showSidebar: false, showSidebar: false,
navigationMenuQueryParamOverride: null,
sidebarDisabledRouteOverride: false, sidebarDisabledRouteOverride: false,
navigationMenuQueryParamOverride: null,
showSiteHeader: true, showSiteHeader: true,
init() { init() {
@ -67,31 +68,24 @@ export default Controller.extend({
document.body.classList.remove("sidebar-animate"); document.body.classList.remove("sidebar-animate");
}, },
@discourseComputed( get sidebarEnabled() {
"navigationMenuQueryParamOverride", if (!this.canDisplaySidebar) {
"siteSettings.navigation_menu",
"canDisplaySidebar",
"sidebarDisabledRouteOverride"
)
sidebarEnabled(
navigationMenuQueryParamOverride,
navigationMenu,
canDisplaySidebar,
sidebarDisabledRouteOverride
) {
if (!canDisplaySidebar) {
return false; return false;
} }
if (sidebarDisabledRouteOverride) { if (this.sidebarState.sidebarHidden) {
return false; return false;
} }
if (navigationMenuQueryParamOverride === "sidebar") { if (this.sidebarDisabledRouteOverride) {
return false;
}
if (this.navigationMenuQueryParamOverride === "sidebar") {
return true; return true;
} }
if (navigationMenuQueryParamOverride === "header_dropdown") { if (this.navigationMenuQueryParamOverride === "header_dropdown") {
return false; return false;
} }
@ -100,7 +94,7 @@ export default Controller.extend({
return false; return false;
} }
return navigationMenu === "sidebar"; return this.siteSettings.navigation_menu === "sidebar";
}, },
calculateShowSidebar() { calculateShowSidebar() {

View File

@ -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() {}
}

View File

@ -1,7 +1,13 @@
import Mixin from "@ember/object/mixin"; import Mixin from "@ember/object/mixin";
import deprecated from "discourse-common/lib/deprecated";
export default Mixin.create({ export default Mixin.create({
activate() { 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({ this.controllerFor("application").setProperties({
sidebarDisabledRouteOverride: true, sidebarDisabledRouteOverride: true,
}); });

View File

@ -1,10 +1,9 @@
import PreloadStore from "discourse/lib/preload-store"; import PreloadStore from "discourse/lib/preload-store";
import DisableSidebar from "discourse/mixins/disable-sidebar";
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
import { deepMerge } from "discourse-common/lib/object"; import { deepMerge } from "discourse-common/lib/object";
import I18n from "discourse-i18n"; import I18n from "discourse-i18n";
export default DiscourseRoute.extend(DisableSidebar, { export default DiscourseRoute.extend({
titleToken() { titleToken() {
return I18n.t("invites.accept_title"); return I18n.t("invites.accept_title");
}, },

View File

@ -1,10 +1,9 @@
import { ajax } from "discourse/lib/ajax"; import { ajax } from "discourse/lib/ajax";
import { extractError } from "discourse/lib/ajax-error"; import { extractError } from "discourse/lib/ajax-error";
import PreloadStore from "discourse/lib/preload-store"; import PreloadStore from "discourse/lib/preload-store";
import DisableSidebar from "discourse/mixins/disable-sidebar";
import DiscourseRoute from "discourse/routes/discourse"; import DiscourseRoute from "discourse/routes/discourse";
export default DiscourseRoute.extend(DisableSidebar, { export default DiscourseRoute.extend({
queryParams: { queryParams: {
nonce: { refreshModel: true }, nonce: { refreshModel: true },
}, },

View File

@ -1,8 +1,7 @@
import Route from "@ember/routing/route"; import Route from "@ember/routing/route";
import DisableSidebar from "discourse/mixins/disable-sidebar";
import Wizard from "discourse/static/wizard/models/wizard"; import Wizard from "discourse/static/wizard/models/wizard";
export default class WizardRoute extends Route.extend(DisableSidebar) { export default class WizardRoute extends Route {
model() { model() {
return Wizard.load(); return Wizard.load();
} }

View File

@ -1,6 +1,8 @@
import { tracked } from "@glimmer/tracking"; import { tracked } from "@glimmer/tracking";
import { A } from "@ember/array"; import { A } from "@ember/array";
import { registerDestructor } from "@ember/destroyable";
import Service, { service } from "@ember/service"; import Service, { service } from "@ember/service";
import { TrackedSet } from "@ember-compat/tracked-built-ins";
import { disableImplicitInjections } from "discourse/lib/implicit-injections"; import { disableImplicitInjections } from "discourse/lib/implicit-injections";
import { import {
currentPanelKey, currentPanelKey,
@ -23,12 +25,25 @@ export default class SidebarState extends Service {
@tracked collapsedSections = A([]); @tracked collapsedSections = A([]);
previousState = {}; previousState = {};
#hiders = new TrackedSet();
constructor() { constructor() {
super(...arguments); super(...arguments);
this.#reset(); this.#reset();
} }
get sidebarHidden() {
return this.#hiders.size > 0;
}
registerHider(ref) {
this.#hiders.add(ref);
registerDestructor(ref, () => {
this.#hiders.delete(ref);
});
}
setPanel(name) { setPanel(name) {
if (this.currentPanelKey) { if (this.currentPanelKey) {
this.setPreviousState(); this.setPreviousState();

View File

@ -1,4 +1,5 @@
{{body-class "invite-page"}} {{body-class "invite-page"}}
{{hide-application-sidebar}}
<section> <section>
<div class="container invites-show clearfix"> <div class="container invites-show clearfix">

View File

@ -1,3 +1,5 @@
{{hide-application-sidebar}}
{{#if this.message}} {{#if this.message}}
<div class="alert {{this.alertClass}}">{{this.message}}</div> <div class="alert {{this.alertClass}}">{{this.message}}</div>
{{/if}} {{/if}}

View File

@ -1,8 +1,10 @@
import RouteTemplate from "ember-route-template"; import RouteTemplate from "ember-route-template";
import hideApplicationFooter from "discourse/helpers/hide-application-footer"; 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"; import DiscourseLogo from "discourse/static/wizard/components/discourse-logo";
export default RouteTemplate(<template> export default RouteTemplate(<template>
{{hideApplicationSidebar}}
{{hideApplicationFooter}} {{hideApplicationFooter}}
<div id="wizard-main"> <div id="wizard-main">
<DiscourseLogo /> <DiscourseLogo />