fix(infra): create template workspace with isolated nanoid (#4569)

This commit is contained in:
Alex Yang
2023-10-11 13:48:30 -05:00
committed by GitHub
parent 5be5863693
commit 491cd75fe0
10 changed files with 108 additions and 52 deletions

View File

@@ -1,6 +1,5 @@
import { DebugLogger } from '@affine/debug';
import {
DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX,
DEFAULT_WORKSPACE_NAME,
PageNotFoundError,
} from '@affine/env/constant';
@@ -61,8 +60,9 @@ export const LocalAdapter: WorkspaceAdapter<WorkspaceFlavour.LOCAL> = {
logger.error('init page with preloading failed', err);
});
} else {
const page = blockSuiteWorkspace.createPage({
id: `${blockSuiteWorkspace.id}-${DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX}`,
const page = blockSuiteWorkspace.createPage();
blockSuiteWorkspace.setPageMeta(page.id, {
jumpOnce: true,
});
initEmptyPage(page).catch(error => {
logger.error('init page with empty failed', error);

View File

@@ -1,5 +1,4 @@
import { DebugLogger } from '@affine/debug';
import { DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX } from '@affine/env/constant';
import { rootWorkspacesMetadataAtom } from '@affine/workspace/atom';
import { Menu } from '@toeverything/components/menu';
import { getWorkspace } from '@toeverything/infra/__internal__/workspace';
@@ -32,10 +31,7 @@ export const loader: LoaderFunction = async () => {
const nonTrashPages = targetWorkspace.meta.pageMetas.filter(
({ trash }) => !trash
);
const helloWorldPage = nonTrashPages.find(
({ id, jumpOnce }) =>
id.endsWith(DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX) && jumpOnce
)?.id;
const helloWorldPage = nonTrashPages.find(({ jumpOnce }) => jumpOnce)?.id;
const pageId =
nonTrashPages.find(({ id }) => id === lastPageId)?.id ??
nonTrashPages.at(0)?.id;