fix: page validation logic (#3626)

This commit is contained in:
Alex Yang
2023-08-08 20:37:53 -04:00
committed by GitHub
parent 4d6e28c725
commit 4472a2a0b0
8 changed files with 67 additions and 114 deletions

View File

@@ -95,32 +95,34 @@ const BlockSuiteEditorImpl = (props: EditorProps): ReactElement => {
if (!container) {
return;
}
if (page.awarenessStore.getFlag('enable_block_hub')) {
editor
.createBlockHub()
.then(blockHub => {
if (blockHubRef.current) {
blockHubRef.current.remove();
}
blockHubRef.current = blockHub;
if (setBlockHub) {
setBlockHub(blockHub);
}
})
.catch(err => {
console.error(err);
});
}
container.appendChild(editor);
return () => {
container.removeChild(editor);
};
}, [editor]);
useEffect(() => {
editor
.createBlockHub()
.then(blockHub => {
if (blockHubRef.current) {
blockHubRef.current.remove();
}
blockHubRef.current = blockHub;
if (setBlockHub) {
setBlockHub(blockHub);
}
})
.catch(err => {
console.error(err);
});
return () => {
if (setBlockHub) {
setBlockHub(null);
}
blockHubRef.current?.remove();
container.removeChild(editor);
};
}, [editor, setBlockHub, page]);
}, [editor, page.awarenessStore, setBlockHub]);
// issue: https://github.com/toeverything/AFFiNE/issues/2004
const className = `editor-wrapper ${editor.mode}-mode ${