fix: first page id conflict (#3192)
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { DebugLogger } from '@affine/debug';
|
import { DebugLogger } from '@affine/debug';
|
||||||
import { initEmptyPage, initPageWithPreloading } from '@affine/env/blocksuite';
|
import { initEmptyPage, initPageWithPreloading } from '@affine/env/blocksuite';
|
||||||
import {
|
import {
|
||||||
DEFAULT_HELLO_WORLD_PAGE_ID,
|
DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX,
|
||||||
DEFAULT_WORKSPACE_NAME,
|
DEFAULT_WORKSPACE_NAME,
|
||||||
PageNotFoundError,
|
PageNotFoundError,
|
||||||
} from '@affine/env/constant';
|
} from '@affine/env/constant';
|
||||||
@@ -42,7 +42,7 @@ export const LocalAdapter: WorkspaceAdapter<WorkspaceFlavour.LOCAL> = {
|
|||||||
);
|
);
|
||||||
blockSuiteWorkspace.meta.setName(DEFAULT_WORKSPACE_NAME);
|
blockSuiteWorkspace.meta.setName(DEFAULT_WORKSPACE_NAME);
|
||||||
const page = blockSuiteWorkspace.createPage({
|
const page = blockSuiteWorkspace.createPage({
|
||||||
id: DEFAULT_HELLO_WORLD_PAGE_ID,
|
id: `${blockSuiteWorkspace.id}-${DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX}`,
|
||||||
});
|
});
|
||||||
if (runtimeConfig.enablePreloading) {
|
if (runtimeConfig.enablePreloading) {
|
||||||
initPageWithPreloading(page).catch(err => {
|
initPageWithPreloading(page).catch(err => {
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import './page-detail-editor.css';
|
import './page-detail-editor.css';
|
||||||
|
|
||||||
import {
|
import { PageNotFoundError } from '@affine/env/constant';
|
||||||
DEFAULT_HELLO_WORLD_PAGE_ID,
|
|
||||||
PageNotFoundError,
|
|
||||||
} from '@affine/env/constant';
|
|
||||||
import { rootBlockHubAtom } from '@affine/workspace/atom';
|
import { rootBlockHubAtom } from '@affine/workspace/atom';
|
||||||
import type { EditorContainer } from '@blocksuite/editor';
|
import type { EditorContainer } from '@blocksuite/editor';
|
||||||
import { assertExists } from '@blocksuite/global/utils';
|
import { assertExists } from '@blocksuite/global/utils';
|
||||||
@@ -61,9 +58,7 @@ const EditorWrapper = memo(function EditorWrapper({
|
|||||||
);
|
);
|
||||||
const pageSettingAtom = pageSettingFamily(pageId);
|
const pageSettingAtom = pageSettingFamily(pageId);
|
||||||
const pageSetting = useAtomValue(pageSettingAtom);
|
const pageSetting = useAtomValue(pageSettingAtom);
|
||||||
const currentMode =
|
const currentMode = pageSetting?.mode ?? 'page';
|
||||||
pageSetting?.mode ??
|
|
||||||
(DEFAULT_HELLO_WORLD_PAGE_ID === pageId ? 'edgeless' : 'page');
|
|
||||||
|
|
||||||
const setBlockHub = useSetAtom(rootBlockHubAtom);
|
const setBlockHub = useSetAtom(rootBlockHubAtom);
|
||||||
const [appSettings] = useAppSetting();
|
const [appSettings] = useAppSetting();
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ import {
|
|||||||
WorkspaceFallback,
|
WorkspaceFallback,
|
||||||
} from '@affine/component/workspace';
|
} from '@affine/component/workspace';
|
||||||
import { initEmptyPage, initPageWithPreloading } from '@affine/env/blocksuite';
|
import { initEmptyPage, initPageWithPreloading } from '@affine/env/blocksuite';
|
||||||
import { DEFAULT_HELLO_WORLD_PAGE_ID, isDesktop } from '@affine/env/constant';
|
import {
|
||||||
|
DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX,
|
||||||
|
isDesktop,
|
||||||
|
} from '@affine/env/constant';
|
||||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||||
import {
|
import {
|
||||||
rootBlockHubAtom,
|
rootBlockHubAtom,
|
||||||
@@ -188,7 +191,7 @@ export const WorkspaceLayoutInner: FC<PropsWithChildren> = ({ children }) => {
|
|||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
if (currentWorkspace.blockSuiteWorkspace.meta._proxy.isEmpty !== true) {
|
if (currentWorkspace.blockSuiteWorkspace.meta._proxy.isEmpty !== true) {
|
||||||
// this is a new workspace, so we should redirect to the new page
|
// this is a new workspace, so we should redirect to the new page
|
||||||
const pageId = DEFAULT_HELLO_WORLD_PAGE_ID;
|
const pageId = `${currentWorkspace.blockSuiteWorkspace.id}-${DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX}`;
|
||||||
if (currentWorkspace.blockSuiteWorkspace.getPage(pageId) === null) {
|
if (currentWorkspace.blockSuiteWorkspace.getPage(pageId) === null) {
|
||||||
const page = currentWorkspace.blockSuiteWorkspace.createPage({
|
const page = currentWorkspace.blockSuiteWorkspace.createPage({
|
||||||
id: pageId,
|
id: pageId,
|
||||||
@@ -218,11 +221,11 @@ export const WorkspaceLayoutInner: FC<PropsWithChildren> = ({ children }) => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const page = currentWorkspace.blockSuiteWorkspace.getPage(
|
const page = currentWorkspace.blockSuiteWorkspace.getPage(
|
||||||
DEFAULT_HELLO_WORLD_PAGE_ID
|
`${currentWorkspace.blockSuiteWorkspace.id}-${DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX}`
|
||||||
);
|
);
|
||||||
if (page && page.meta.jumpOnce) {
|
if (page && page.meta.jumpOnce) {
|
||||||
currentWorkspace.blockSuiteWorkspace.meta.setPageMeta(
|
currentWorkspace.blockSuiteWorkspace.meta.setPageMeta(
|
||||||
DEFAULT_HELLO_WORLD_PAGE_ID,
|
`${currentWorkspace.blockSuiteWorkspace.id}-${DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX}`,
|
||||||
{
|
{
|
||||||
jumpOnce: false,
|
jumpOnce: false,
|
||||||
}
|
}
|
||||||
|
|||||||
3
packages/env/src/constant.ts
vendored
3
packages/env/src/constant.ts
vendored
@@ -14,10 +14,9 @@ export const isBrowser = typeof window !== 'undefined';
|
|||||||
export const isServer = !isBrowser && typeof navigator === 'undefined';
|
export const isServer = !isBrowser && typeof navigator === 'undefined';
|
||||||
export const isDesktop = isBrowser && !!window.appInfo?.electron;
|
export const isDesktop = isBrowser && !!window.appInfo?.electron;
|
||||||
//#endregion
|
//#endregion
|
||||||
export const AFFINE_STORAGE_KEY = 'affine-local-storage-v2';
|
|
||||||
export const DEFAULT_WORKSPACE_NAME = 'Demo Workspace';
|
export const DEFAULT_WORKSPACE_NAME = 'Demo Workspace';
|
||||||
export const UNTITLED_WORKSPACE_NAME = 'Untitled';
|
export const UNTITLED_WORKSPACE_NAME = 'Untitled';
|
||||||
export const DEFAULT_HELLO_WORLD_PAGE_ID = 'hello-world';
|
export const DEFAULT_HELLO_WORLD_PAGE_ID_SUFFIX = 'hello-world';
|
||||||
|
|
||||||
export const DEFAULT_SORT_KEY = 'updatedDate';
|
export const DEFAULT_SORT_KEY = 'updatedDate';
|
||||||
export const MessageCode = {
|
export const MessageCode = {
|
||||||
|
|||||||
Reference in New Issue
Block a user