refactor(core): refactor left sidebar to use di (#8385)

This commit is contained in:
JimmFly
2024-09-27 09:32:24 +00:00
parent 0f9fac420f
commit a3f8e6c852
54 changed files with 316 additions and 180 deletions

View File

@@ -1,17 +1,16 @@
import type { useI18n } from '@affine/i18n';
import { track } from '@affine/track';
import { SidebarIcon } from '@blocksuite/icons/rc';
import type { createStore } from 'jotai';
import { appSidebarOpenAtom } from '../components/app-sidebar';
import type { AppSidebarService } from '../modules/app-sidebar';
import { registerAffineCommand } from './registry';
export function registerAffineLayoutCommands({
t,
store,
appSidebarService,
}: {
t: ReturnType<typeof useI18n>;
store: ReturnType<typeof createStore>;
appSidebarService: AppSidebarService;
}) {
const unsubs: Array<() => void> = [];
unsubs.push(
@@ -20,7 +19,7 @@ export function registerAffineLayoutCommands({
category: 'affine:layout',
icon: <SidebarIcon />,
label: () =>
store.get(appSidebarOpenAtom)
appSidebarService.sidebar.open$.value
? t['com.affine.cmdk.affine.left-sidebar.collapse']()
: t['com.affine.cmdk.affine.left-sidebar.expand'](),
@@ -29,8 +28,7 @@ export function registerAffineLayoutCommands({
},
run() {
track.$.navigationPanel.$.toggle();
store.set(appSidebarOpenAtom, v => !v);
appSidebarService.sidebar.toggleSidebar();
},
})
);