mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-10 13:38:49 +08:00
refactor!: next generation AFFiNE code structure (#1176)
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { assertExists } from '@blocksuite/store';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { BlockSuiteWorkspace } from '../shared';
|
||||
|
||||
export function useBlockSuiteWorkspaceHelper(
|
||||
blockSuiteWorkspace: BlockSuiteWorkspace | null
|
||||
) {
|
||||
return useMemo(
|
||||
() => ({
|
||||
createPage: (pageId: string, title?: string): Promise<string> => {
|
||||
return new Promise(resolve => {
|
||||
assertExists(blockSuiteWorkspace);
|
||||
const dispose = blockSuiteWorkspace.signals.pageAdded.on(id => {
|
||||
if (id === pageId) {
|
||||
dispose.dispose();
|
||||
// Fixme: https://github.com/toeverything/blocksuite/issues/1350
|
||||
setTimeout(() => {
|
||||
resolve(pageId);
|
||||
}, 0);
|
||||
}
|
||||
});
|
||||
blockSuiteWorkspace.createPage(pageId);
|
||||
});
|
||||
},
|
||||
}),
|
||||
[blockSuiteWorkspace]
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user