feat(core): save user habits in right sidebar (#6262)

Closes #6237
This commit is contained in:
EYHN
2024-03-22 07:32:59 +00:00
parent 85ee22329c
commit 75355867c7
3 changed files with 34 additions and 9 deletions

View File

@@ -1,9 +1,16 @@
import { LiveData } from '@toeverything/infra/livedata';
import type { GlobalState } from '@toeverything/infra/storage';
import type { RightSidebarView } from './right-sidebar-view';
const RIGHT_SIDEBAR_KEY = 'app:settings:rightsidebar';
export class RightSidebar {
readonly isOpen = new LiveData(false);
constructor(private readonly globalState: GlobalState) {}
readonly isOpen = LiveData.from(
this.globalState.watch<boolean>(RIGHT_SIDEBAR_KEY),
false
).map(Boolean);
readonly views = new LiveData<RightSidebarView[]>([]);
readonly front = this.views.map(
stack => stack[0] as RightSidebarView | undefined
@@ -11,15 +18,19 @@ export class RightSidebar {
readonly hasViews = this.views.map(stack => stack.length > 0);
open() {
this.isOpen.next(true);
this._set(true);
}
toggle() {
this.isOpen.next(!this.isOpen.value);
this._set(!this.isOpen.value);
}
close() {
this.isOpen.next(false);
this._set(false);
}
_set(value: boolean) {
this.globalState.set(RIGHT_SIDEBAR_KEY, value);
}
/**

View File

@@ -28,7 +28,7 @@ export function configureBusinessServices(services: ServiceCollection) {
.scope(WorkspaceScope)
.add(Workbench)
.add(Navigator, [Workbench])
.add(RightSidebar)
.add(RightSidebar, [GlobalState])
.add(WorkspacePropertiesAdapter, [Workspace])
.add(CollectionService, [Workspace])
.add(WorkspaceLegacyProperties, [Workspace])