mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
refactor(core): refactor atom to use di (#5831)
To support multiple instances, this PR removes some atoms and implements them using the new DI system. removed atom - `pageSettingsAtom` - `currentPageIdAtom` - `currentModeAtom`
This commit is contained in:
@@ -2,42 +2,36 @@ import { DebugLogger } from '@affine/debug';
|
||||
import { DEFAULT_WORKSPACE_NAME } from '@affine/env/constant';
|
||||
import { WorkspaceFlavour } from '@affine/env/workspace';
|
||||
import type { WorkspaceManager } from '@toeverything/infra';
|
||||
import { getCurrentStore } from '@toeverything/infra/atom';
|
||||
import {
|
||||
buildShowcaseWorkspace,
|
||||
initEmptyPage,
|
||||
} from '@toeverything/infra/blocksuite';
|
||||
import { buildShowcaseWorkspace, initEmptyPage } from '@toeverything/infra';
|
||||
|
||||
import { setPageModeAtom } from '../atoms';
|
||||
|
||||
const logger = new DebugLogger('affine:first-app-data');
|
||||
const logger = new DebugLogger('createFirstAppData');
|
||||
|
||||
export async function createFirstAppData(workspaceManager: WorkspaceManager) {
|
||||
if (localStorage.getItem('is-first-open') !== null) {
|
||||
return;
|
||||
}
|
||||
localStorage.setItem('is-first-open', 'false');
|
||||
const workspaceMetadata = await workspaceManager.createWorkspace(
|
||||
WorkspaceFlavour.LOCAL,
|
||||
async workspace => {
|
||||
workspace.meta.setName(DEFAULT_WORKSPACE_NAME);
|
||||
if (runtimeConfig.enablePreloading) {
|
||||
await buildShowcaseWorkspace(workspace, {
|
||||
store: getCurrentStore(),
|
||||
atoms: {
|
||||
pageMode: setPageModeAtom,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
if (runtimeConfig.enablePreloading) {
|
||||
const workspaceMetadata = await buildShowcaseWorkspace(
|
||||
workspaceManager,
|
||||
WorkspaceFlavour.LOCAL,
|
||||
DEFAULT_WORKSPACE_NAME
|
||||
);
|
||||
logger.info('create first workspace', workspaceMetadata);
|
||||
return workspaceMetadata;
|
||||
} else {
|
||||
const workspaceMetadata = await workspaceManager.createWorkspace(
|
||||
WorkspaceFlavour.LOCAL,
|
||||
async workspace => {
|
||||
workspace.meta.setName(DEFAULT_WORKSPACE_NAME);
|
||||
const page = workspace.createPage();
|
||||
workspace.setPageMeta(page.id, {
|
||||
jumpOnce: true,
|
||||
});
|
||||
initEmptyPage(page);
|
||||
}
|
||||
logger.debug('create first workspace');
|
||||
}
|
||||
);
|
||||
console.info('create first workspace', workspaceMetadata);
|
||||
return workspaceMetadata;
|
||||
);
|
||||
logger.info('create first workspace', workspaceMetadata);
|
||||
return workspaceMetadata;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user