fix: new page logic (#1621)

This commit is contained in:
Himself65
2023-03-20 02:39:18 -05:00
committed by GitHub
parent fe2d244460
commit cf3230c1ff
6 changed files with 17 additions and 31 deletions
@@ -1,3 +1,4 @@
import type { Page } from '@blocksuite/store';
import { assertExists } from '@blocksuite/store';
import { useMemo } from 'react';
@@ -8,20 +9,9 @@ export function useBlockSuiteWorkspaceHelper(
) {
return useMemo(
() => ({
createPage: (pageId: string, title?: string): Promise<string> => {
return new Promise(resolve => {
assertExists(blockSuiteWorkspace);
const dispose = blockSuiteWorkspace.slots.pageAdded.on(id => {
if (id === pageId) {
dispose.dispose();
// Fixme: https://github.com/toeverything/blocksuite/issues/1350
setTimeout(() => {
resolve(pageId);
}, 0);
}
});
blockSuiteWorkspace.createPage(pageId);
});
createPage: (pageId: string, title?: string): Page => {
assertExists(blockSuiteWorkspace);
return blockSuiteWorkspace.createPage(pageId);
},
}),
[blockSuiteWorkspace]