mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-01 01:29:31 +08:00
refactor(infra): migrate to new infra (#5565)
This commit is contained in:
@@ -8,10 +8,8 @@ import MockSessionContext, {
|
||||
import { ThemeProvider, useTheme } from 'next-themes';
|
||||
import { useDarkMode } from 'storybook-dark-mode';
|
||||
import { AffineContext } from '@affine/component/context';
|
||||
import { workspaceManager } from '@affine/workspace-impl';
|
||||
import useSWR from 'swr';
|
||||
import type { Decorator } from '@storybook/react';
|
||||
import { createStore } from 'jotai/vanilla';
|
||||
import { _setCurrentStore } from '@toeverything/infra/atom';
|
||||
import { setupGlobal, type Environment } from '@affine/env/global';
|
||||
|
||||
@@ -19,7 +17,16 @@ import type { Preview } from '@storybook/react';
|
||||
import { useLayoutEffect, useRef } from 'react';
|
||||
import { setup } from '@affine/core/bootstrap/setup';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { currentWorkspaceAtom } from '@affine/core/modules/workspace';
|
||||
import { ServiceCollection } from '@toeverything/infra/di';
|
||||
import {
|
||||
WorkspaceManager,
|
||||
configureInfraServices,
|
||||
configureTestingInfraServices,
|
||||
} from '@toeverything/infra';
|
||||
import { CurrentWorkspaceService } from '@affine/core/modules/workspace';
|
||||
import { configureBusinessServices } from '@affine/core/modules/services';
|
||||
import { createStore } from 'jotai';
|
||||
import { GlobalScopeProvider } from '@affine/core/modules/infra-web/global-scope';
|
||||
|
||||
setupGlobal();
|
||||
export const parameters = {
|
||||
@@ -112,29 +119,42 @@ window.localStorage.setItem(
|
||||
'{"onBoarding":false, "dismissWorkspaceGuideModal":true}'
|
||||
);
|
||||
|
||||
const services = new ServiceCollection();
|
||||
|
||||
configureInfraServices(services);
|
||||
configureTestingInfraServices(services);
|
||||
configureBusinessServices(services);
|
||||
|
||||
const provider = services.provider();
|
||||
|
||||
const store = createStore();
|
||||
_setCurrentStore(store);
|
||||
setup();
|
||||
workspaceManager
|
||||
|
||||
provider
|
||||
.get(WorkspaceManager)
|
||||
.createWorkspace(WorkspaceFlavour.LOCAL, async w => {
|
||||
w.meta.setName('test-workspace');
|
||||
w.meta.writeVersion(w);
|
||||
})
|
||||
.then(id => {
|
||||
store.set(
|
||||
currentWorkspaceAtom,
|
||||
workspaceManager.use({ flavour: WorkspaceFlavour.LOCAL, id }).workspace
|
||||
.then(workspaceMetadata => {
|
||||
const currentWorkspace = provider.get(CurrentWorkspaceService);
|
||||
const workspaceManager = provider.get(WorkspaceManager);
|
||||
currentWorkspace.openWorkspace(
|
||||
workspaceManager.open(workspaceMetadata).workspace
|
||||
);
|
||||
});
|
||||
|
||||
const withContextDecorator: Decorator = (Story, context) => {
|
||||
return (
|
||||
<ThemeProvider>
|
||||
<AffineContext store={store}>
|
||||
<ThemeChange />
|
||||
<Story {...context} />
|
||||
</AffineContext>
|
||||
</ThemeProvider>
|
||||
<GlobalScopeProvider provider={provider}>
|
||||
<ThemeProvider>
|
||||
<AffineContext store={store}>
|
||||
<ThemeChange />
|
||||
<Story {...context} />
|
||||
</AffineContext>
|
||||
</ThemeProvider>
|
||||
</GlobalScopeProvider>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { BlockSuiteEditor } from '@affine/core/components/blocksuite/block-suite-editor';
|
||||
import { ImagePreviewModal } from '@affine/core/components/image-preview';
|
||||
import { waitForCurrentWorkspaceAtom } from '@affine/core/modules/workspace';
|
||||
import type { Page } from '@blocksuite/store';
|
||||
import type { Meta } from '@storybook/react';
|
||||
import { useService, Workspace } from '@toeverything/infra';
|
||||
import { initEmptyPage } from '@toeverything/infra/blocksuite';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
|
||||
@@ -14,7 +13,7 @@ export default {
|
||||
} satisfies Meta;
|
||||
|
||||
export const Default = () => {
|
||||
const workspace = useAtomValue(waitForCurrentWorkspaceAtom);
|
||||
const workspace = useService(Workspace);
|
||||
|
||||
const [page, setPage] = useState<Page | null>(null);
|
||||
|
||||
|
||||
@@ -5,14 +5,11 @@ import {
|
||||
} from '@affine/core/commands';
|
||||
import { CMDKQuickSearchModal } from '@affine/core/components/pure/cmdk';
|
||||
import { HighlightLabel } from '@affine/core/components/pure/cmdk/highlight';
|
||||
import { useWorkspace } from '@affine/core/hooks/use-workspace';
|
||||
import { currentWorkspaceAtom } from '@affine/core/modules/workspace';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||
import type { Page } from '@blocksuite/store';
|
||||
import type { Meta, StoryFn } from '@storybook/react';
|
||||
import { useStore } from 'jotai';
|
||||
import { useEffect, useLayoutEffect, useState } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { withRouter } from 'storybook-addon-react-router-v6';
|
||||
|
||||
export default {
|
||||
@@ -79,20 +76,7 @@ function useRegisterCommands() {
|
||||
}, [store, t]);
|
||||
}
|
||||
|
||||
function usePrepareWorkspace() {
|
||||
const workspaceId = 'test-workspace';
|
||||
const store = useStore();
|
||||
const workspace = useWorkspace({
|
||||
id: workspaceId,
|
||||
flavour: WorkspaceFlavour.LOCAL,
|
||||
});
|
||||
useLayoutEffect(() => {
|
||||
store.set(currentWorkspaceAtom, workspace);
|
||||
}, [store, workspace]);
|
||||
}
|
||||
|
||||
export const CMDKStoryWithCommands: StoryFn = () => {
|
||||
usePrepareWorkspace();
|
||||
useRegisterCommands();
|
||||
|
||||
return <CMDKQuickSearchModal open />;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { toast } from '@affine/component';
|
||||
import { PublicLinkDisableModal } from '@affine/component/disable-public-link';
|
||||
import { ShareMenu } from '@affine/core/components/affine/share-page-modal/share-menu';
|
||||
import { waitForCurrentWorkspaceAtom } from '@affine/core/modules/workspace';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import { type Page } from '@blocksuite/store';
|
||||
import { expect } from '@storybook/jest';
|
||||
import type { Meta, StoryFn } from '@storybook/react';
|
||||
import { Workspace } from '@toeverything/infra';
|
||||
import { initEmptyPage } from '@toeverything/infra/blocksuite';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { useService } from '@toeverything/infra/di';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
@@ -24,7 +24,7 @@ async function unimplemented() {
|
||||
}
|
||||
|
||||
export const Basic: StoryFn = () => {
|
||||
const workspace = useAtomValue(waitForCurrentWorkspaceAtom);
|
||||
const workspace = useService(Workspace);
|
||||
|
||||
const [page, setPage] = useState<Page | null>(null);
|
||||
|
||||
@@ -66,7 +66,7 @@ Basic.play = async ({ canvasElement }) => {
|
||||
};
|
||||
|
||||
export const AffineBasic: StoryFn = () => {
|
||||
const workspace = useAtomValue(waitForCurrentWorkspaceAtom);
|
||||
const workspace = useService(Workspace);
|
||||
|
||||
const [page, setPage] = useState<Page | null>(null);
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { WorkspaceListProps } from '@affine/component/workspace-list';
|
||||
import { WorkspaceList } from '@affine/component/workspace-list';
|
||||
import { workspaceListAtom } from '@affine/core/modules/workspace';
|
||||
import type { Meta } from '@storybook/react';
|
||||
import { useAtomValue } from 'jotai';
|
||||
import { WorkspaceManager } from '@toeverything/infra';
|
||||
import { useLiveData, useService } from '@toeverything/infra';
|
||||
|
||||
export default {
|
||||
title: 'AFFiNE/WorkspaceList',
|
||||
@@ -13,7 +13,7 @@ export default {
|
||||
} satisfies Meta<WorkspaceListProps>;
|
||||
|
||||
export const Default = () => {
|
||||
const list = useAtomValue(workspaceListAtom);
|
||||
const list = useLiveData(useService(WorkspaceManager).list.workspaceList);
|
||||
return (
|
||||
<WorkspaceList
|
||||
currentWorkspaceId={null}
|
||||
|
||||
@@ -21,9 +21,6 @@
|
||||
{
|
||||
"path": "../../packages/common/infra"
|
||||
},
|
||||
{
|
||||
"path": "../../packages/common/workspace"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.node.json"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user