DEV: Fix `sidebar-hidden` localStorage value (#17915)

Previously ,`undefined` value for `sidebar-hidden` would mean "hide". Not it uses `true`.

Also, extract it into a const.
This commit is contained in:
Jarek Radosz 2022-08-15 03:35:01 +02:00 committed by GitHub
parent afaa2d5417
commit cac1608213
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 7 deletions

View File

@ -4,22 +4,24 @@ import discourseDebounce from "discourse-common/lib/debounce";
import { inject as service } from "@ember/service";
import { action } from "@ember/object";
const HIDE_SIDEBAR_KEY = "sidebar-hidden";
export default Controller.extend({
queryParams: ["enable_sidebar"],
showTop: true,
showFooter: false,
router: service(),
showSidebar: null,
hideSidebarKey: "sidebar-hidden",
showSidebar: false,
enable_sidebar: null,
init() {
this._super(...arguments);
this.showSidebar = this.site.mobileView
? false
: this.currentUser && !this.keyValueStore.getItem(this.hideSidebarKey);
this.showSidebar =
this.currentUser &&
!this.site.mobileView &&
!this.keyValueStore.getItem(HIDE_SIDEBAR_KEY);
},
@discourseComputed
@ -86,9 +88,9 @@ export default Controller.extend({
if (this.site.desktopView) {
if (this.showSidebar) {
this.keyValueStore.removeItem(this.hideSidebarKey);
this.keyValueStore.removeItem(HIDE_SIDEBAR_KEY);
} else {
this.keyValueStore.setItem(this.hideSidebarKey);
this.keyValueStore.setItem(HIDE_SIDEBAR_KEY, "true");
}
}
},