@@ -1,9 +1,16 @@
|
|||||||
import { LiveData } from '@toeverything/infra/livedata';
|
import { LiveData } from '@toeverything/infra/livedata';
|
||||||
|
import type { GlobalState } from '@toeverything/infra/storage';
|
||||||
|
|
||||||
import type { RightSidebarView } from './right-sidebar-view';
|
import type { RightSidebarView } from './right-sidebar-view';
|
||||||
|
|
||||||
|
const RIGHT_SIDEBAR_KEY = 'app:settings:rightsidebar';
|
||||||
|
|
||||||
export class 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 views = new LiveData<RightSidebarView[]>([]);
|
||||||
readonly front = this.views.map(
|
readonly front = this.views.map(
|
||||||
stack => stack[0] as RightSidebarView | undefined
|
stack => stack[0] as RightSidebarView | undefined
|
||||||
@@ -11,15 +18,19 @@ export class RightSidebar {
|
|||||||
readonly hasViews = this.views.map(stack => stack.length > 0);
|
readonly hasViews = this.views.map(stack => stack.length > 0);
|
||||||
|
|
||||||
open() {
|
open() {
|
||||||
this.isOpen.next(true);
|
this._set(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
toggle() {
|
toggle() {
|
||||||
this.isOpen.next(!this.isOpen.value);
|
this._set(!this.isOpen.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
this.isOpen.next(false);
|
this._set(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
_set(value: boolean) {
|
||||||
|
this.globalState.set(RIGHT_SIDEBAR_KEY, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export function configureBusinessServices(services: ServiceCollection) {
|
|||||||
.scope(WorkspaceScope)
|
.scope(WorkspaceScope)
|
||||||
.add(Workbench)
|
.add(Workbench)
|
||||||
.add(Navigator, [Workbench])
|
.add(Navigator, [Workbench])
|
||||||
.add(RightSidebar)
|
.add(RightSidebar, [GlobalState])
|
||||||
.add(WorkspacePropertiesAdapter, [Workspace])
|
.add(WorkspacePropertiesAdapter, [Workspace])
|
||||||
.add(CollectionService, [Workspace])
|
.add(CollectionService, [Workspace])
|
||||||
.add(WorkspaceLegacyProperties, [Workspace])
|
.add(WorkspaceLegacyProperties, [Workspace])
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import type { Doc as BlockSuiteDoc } from '@blocksuite/store';
|
|||||||
import {
|
import {
|
||||||
Doc,
|
Doc,
|
||||||
globalBlockSuiteSchema,
|
globalBlockSuiteSchema,
|
||||||
|
GlobalState,
|
||||||
|
LiveData,
|
||||||
PageManager,
|
PageManager,
|
||||||
PageRecordList,
|
PageRecordList,
|
||||||
ServiceProviderContext,
|
ServiceProviderContext,
|
||||||
@@ -65,7 +67,23 @@ import { PageNotFound } from '../../404';
|
|||||||
import * as styles from './detail-page.css';
|
import * as styles from './detail-page.css';
|
||||||
import { DetailPageHeader } from './detail-page-header';
|
import { DetailPageHeader } from './detail-page-header';
|
||||||
|
|
||||||
|
const RIGHT_SIDEBAR_TABS_ACTIVE_KEY = 'app:settings:rightsidebar:tabs:active';
|
||||||
|
|
||||||
const DetailPageImpl = memo(function DetailPageImpl() {
|
const DetailPageImpl = memo(function DetailPageImpl() {
|
||||||
|
const globalState = useService(GlobalState);
|
||||||
|
const activeTabName = useLiveData(
|
||||||
|
LiveData.from(
|
||||||
|
globalState.watch<SidebarTabName>(RIGHT_SIDEBAR_TABS_ACTIVE_KEY),
|
||||||
|
'journal'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
const setActiveTabName = useCallback(
|
||||||
|
(name: string) => {
|
||||||
|
globalState.set(RIGHT_SIDEBAR_TABS_ACTIVE_KEY, name);
|
||||||
|
},
|
||||||
|
[globalState]
|
||||||
|
);
|
||||||
|
|
||||||
const page = useService(Doc);
|
const page = useService(Doc);
|
||||||
const pageRecordList = useService(PageRecordList);
|
const pageRecordList = useService(PageRecordList);
|
||||||
const currentPageId = page.id;
|
const currentPageId = page.id;
|
||||||
@@ -84,10 +102,6 @@ const DetailPageImpl = memo(function DetailPageImpl() {
|
|||||||
}
|
}
|
||||||
}, [editor, isActiveView, setActiveBlockSuiteEditor]);
|
}, [editor, isActiveView, setActiveBlockSuiteEditor]);
|
||||||
|
|
||||||
const [activeTabName, setActiveTabName] = useState<SidebarTabName | null>(
|
|
||||||
null
|
|
||||||
);
|
|
||||||
|
|
||||||
const pageMeta = useBlockSuiteDocMeta(docCollection).find(
|
const pageMeta = useBlockSuiteDocMeta(docCollection).find(
|
||||||
meta => meta.id === page.id
|
meta => meta.id === page.id
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user