mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 10:42:45 +08:00
DEV: Simplify sidebar's collapsedSections
(#26972)
This commit is contained in:
parent
3e7601cada
commit
4c47f25530
|
@ -1,5 +1,4 @@
|
|||
import Component from "@glimmer/component";
|
||||
import { tracked } from "@glimmer/tracking";
|
||||
import { action } from "@ember/object";
|
||||
import { service } from "@ember/service";
|
||||
import { bind } from "discourse-common/utils/decorators";
|
||||
|
@ -8,7 +7,6 @@ export default class SidebarSection extends Component {
|
|||
@service keyValueStore;
|
||||
@service sidebarState;
|
||||
|
||||
@tracked collapsedSections = this.sidebarState.collapsedSections;
|
||||
sidebarSectionContentID = `sidebar-section-content-${this.args.sectionName}`;
|
||||
collapsedSidebarSectionKey = `sidebar-section-${this.args.sectionName}-collapsed`;
|
||||
|
||||
|
@ -36,7 +34,9 @@ export default class SidebarSection extends Component {
|
|||
}
|
||||
|
||||
get displaySectionContent() {
|
||||
return !this.collapsedSections.includes(this.collapsedSidebarSectionKey);
|
||||
return !this.sidebarState.collapsedSections.has(
|
||||
this.collapsedSidebarSectionKey
|
||||
);
|
||||
}
|
||||
|
||||
willDestroy() {
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import Component from "@glimmer/component";
|
||||
import { tracked } from "@glimmer/tracking";
|
||||
import { action } from "@ember/object";
|
||||
import { service } from "@ember/service";
|
||||
import DButton from "discourse/components/d-button";
|
||||
|
@ -8,11 +7,10 @@ import { ADMIN_NAV_MAP } from "discourse/lib/sidebar/admin-nav-map";
|
|||
export default class ToggleAllSections extends Component {
|
||||
@service sidebarState;
|
||||
@service keyValueStore;
|
||||
@tracked collapsedSections = this.sidebarState.collapsedSections;
|
||||
|
||||
get allSectionsExpanded() {
|
||||
return ADMIN_NAV_MAP.every((adminNav) => {
|
||||
return !this.collapsedSections.includes(
|
||||
return !this.sidebarState.collapsedSections.has(
|
||||
`sidebar-section-${this.sidebarState.currentPanel.key}-${adminNav.name}-collapsed`
|
||||
);
|
||||
});
|
||||
|
@ -32,13 +30,15 @@ export default class ToggleAllSections extends Component {
|
|||
|
||||
@action
|
||||
toggleAllSections() {
|
||||
const collapseOrExpand = this.allSectionsExpanded
|
||||
? this.sidebarState.collapseSection.bind(this)
|
||||
: this.sidebarState.expandSection.bind(this);
|
||||
const collapse = this.allSectionsExpanded;
|
||||
|
||||
ADMIN_NAV_MAP.forEach((adminNav) => {
|
||||
collapseOrExpand(
|
||||
`${this.sidebarState.currentPanel.key}-${adminNav.name}`
|
||||
);
|
||||
const key = `${this.sidebarState.currentPanel.key}-${adminNav.name}`;
|
||||
if (collapse) {
|
||||
this.sidebarState.collapseSection(key);
|
||||
} else {
|
||||
this.sidebarState.expandSection(key);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
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";
|
||||
|
@ -17,21 +16,16 @@ import {
|
|||
@disableImplicitInjections
|
||||
export default class SidebarState extends Service {
|
||||
@service keyValueStore;
|
||||
|
||||
@tracked currentPanelKey = currentPanelKey;
|
||||
@tracked panels = panels;
|
||||
@tracked mode = COMBINED_MODE;
|
||||
@tracked displaySwitchPanelButtons = false;
|
||||
@tracked filter = "";
|
||||
@tracked collapsedSections = A([]);
|
||||
|
||||
panels = panels;
|
||||
collapsedSections = new TrackedSet();
|
||||
previousState = {};
|
||||
#hiders = new TrackedSet();
|
||||
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.#reset();
|
||||
}
|
||||
|
||||
get sidebarHidden() {
|
||||
return this.#hiders.size > 0;
|
||||
}
|
||||
|
@ -85,13 +79,13 @@ export default class SidebarState extends Service {
|
|||
collapseSection(sectionKey) {
|
||||
const collapsedSidebarSectionKey = `sidebar-section-${sectionKey}-collapsed`;
|
||||
this.keyValueStore.setItem(collapsedSidebarSectionKey, true);
|
||||
this.collapsedSections.pushObject(collapsedSidebarSectionKey);
|
||||
this.collapsedSections.add(collapsedSidebarSectionKey);
|
||||
}
|
||||
|
||||
expandSection(sectionKey) {
|
||||
const collapsedSidebarSectionKey = `sidebar-section-${sectionKey}-collapsed`;
|
||||
this.keyValueStore.setItem(collapsedSidebarSectionKey, false);
|
||||
this.collapsedSections.removeObject(collapsedSidebarSectionKey);
|
||||
this.collapsedSections.delete(collapsedSidebarSectionKey);
|
||||
}
|
||||
|
||||
isCurrentPanel(panel) {
|
||||
|
@ -125,12 +119,6 @@ export default class SidebarState extends Service {
|
|||
return this.currentPanelKey === MAIN_PANEL;
|
||||
}
|
||||
|
||||
#reset() {
|
||||
this.currentPanelKey = currentPanelKey;
|
||||
this.panels = panels;
|
||||
this.mode = COMBINED_MODE;
|
||||
}
|
||||
|
||||
clearFilter() {
|
||||
this.filter = "";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user