2024-03-14 09:28:08 +08:00
|
|
|
import { tracked } from "@glimmer/tracking";
|
2024-03-20 07:20:06 +08:00
|
|
|
import Service, { service } from "@ember/service";
|
2024-03-14 09:28:08 +08:00
|
|
|
import { TrackedObject } from "@ember-compat/tracked-built-ins";
|
2023-11-02 08:34:37 +08:00
|
|
|
import KeyValueStore from "discourse/lib/key-value-store";
|
2024-03-20 07:20:06 +08:00
|
|
|
import { ADMIN_PANEL } from "discourse/lib/sidebar/panels";
|
2023-11-02 08:34:37 +08:00
|
|
|
|
2024-03-14 09:28:08 +08:00
|
|
|
export default class AdminSidebarStateManager extends Service {
|
2024-03-20 07:20:06 +08:00
|
|
|
@service sidebarState;
|
|
|
|
@service currentUser;
|
2024-03-14 09:28:08 +08:00
|
|
|
@tracked keywords = new TrackedObject();
|
2024-03-20 07:20:06 +08:00
|
|
|
|
2023-11-02 08:34:37 +08:00
|
|
|
STORE_NAMESPACE = "discourse_admin_sidebar_experiment_";
|
|
|
|
|
|
|
|
store = new KeyValueStore(this.STORE_NAMESPACE);
|
|
|
|
|
|
|
|
get navConfig() {
|
|
|
|
return this.store.getObject("navConfig");
|
|
|
|
}
|
|
|
|
|
|
|
|
set navConfig(value) {
|
|
|
|
this.store.setObject({ key: "navConfig", value });
|
|
|
|
}
|
2024-03-20 07:20:06 +08:00
|
|
|
|
|
|
|
get currentUserUsingAdminSidebar() {
|
|
|
|
return this.currentUser?.use_admin_sidebar;
|
|
|
|
}
|
|
|
|
|
|
|
|
maybeForceAdminSidebar(opts = {}) {
|
|
|
|
opts.onlyIfAlreadyActive ??= true;
|
|
|
|
|
|
|
|
const isAdminSidebarActive =
|
|
|
|
this.sidebarState.currentPanel?.key === ADMIN_PANEL;
|
|
|
|
|
|
|
|
if (!this.currentUserUsingAdminSidebar) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!opts.onlyIfAlreadyActive) {
|
|
|
|
return this.#forceAdminSidebar();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isAdminSidebarActive) {
|
|
|
|
return this.#forceAdminSidebar();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#forceAdminSidebar() {
|
|
|
|
this.sidebarState.setPanel(ADMIN_PANEL);
|
|
|
|
this.sidebarState.setSeparatedMode();
|
|
|
|
this.sidebarState.hideSwitchPanelButtons();
|
|
|
|
return true;
|
|
|
|
}
|
2023-11-02 08:34:37 +08:00
|
|
|
}
|