mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
fix(core): sidebar extension sometimes not show (#5513)
This commit is contained in:
@@ -9,15 +9,7 @@ import { fontStyleOptions } from '@toeverything/infra/atom';
|
|||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import { useAtomValue } from 'jotai';
|
import { useAtomValue } from 'jotai';
|
||||||
import type { CSSProperties } from 'react';
|
import type { CSSProperties } from 'react';
|
||||||
import {
|
import { memo, Suspense, useCallback, useMemo } from 'react';
|
||||||
memo,
|
|
||||||
Suspense,
|
|
||||||
useCallback,
|
|
||||||
useEffect,
|
|
||||||
useMemo,
|
|
||||||
useRef,
|
|
||||||
useState,
|
|
||||||
} from 'react';
|
|
||||||
import { useLocation } from 'react-router-dom';
|
import { useLocation } from 'react-router-dom';
|
||||||
|
|
||||||
import { type PageMode, pageSettingFamily } from '../atoms';
|
import { type PageMode, pageSettingFamily } from '../atoms';
|
||||||
@@ -96,14 +88,14 @@ const PageDetailEditorMain = memo(function PageDetailEditorMain({
|
|||||||
[isPublic, switchToEdgelessMode, pageId, switchToPageMode]
|
[isPublic, switchToEdgelessMode, pageId, switchToPageMode]
|
||||||
);
|
);
|
||||||
|
|
||||||
const [editor, setEditor] = useState<AffineEditorContainer>();
|
const [, setActiveBlocksuiteEditor] = useActiveBlocksuiteEditor();
|
||||||
const blockId = useRouterHash();
|
const blockId = useRouterHash();
|
||||||
|
|
||||||
const onLoadEditor = useCallback(
|
const onLoadEditor = useCallback(
|
||||||
(editor: AffineEditorContainer) => {
|
(editor: AffineEditorContainer) => {
|
||||||
// debug current detail editor
|
// debug current detail editor
|
||||||
globalThis.currentEditor = editor;
|
globalThis.currentEditor = editor;
|
||||||
setEditor(editor);
|
setActiveBlocksuiteEditor(editor);
|
||||||
const disposableGroup = new DisposableGroup();
|
const disposableGroup = new DisposableGroup();
|
||||||
disposableGroup.add(
|
disposableGroup.add(
|
||||||
page.slots.blockUpdated.once(() => {
|
page.slots.blockUpdated.once(() => {
|
||||||
@@ -121,18 +113,9 @@ const PageDetailEditorMain = memo(function PageDetailEditorMain({
|
|||||||
disposableGroup.dispose();
|
disposableGroup.dispose();
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
[onLoad, page]
|
[onLoad, page, setActiveBlocksuiteEditor]
|
||||||
);
|
);
|
||||||
|
|
||||||
const [, setActiveBlocksuiteEditor] = useActiveBlocksuiteEditor();
|
|
||||||
const editorRef = useRef<AffineEditorContainer | null>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (editor) {
|
|
||||||
setActiveBlocksuiteEditor(editorRef.current);
|
|
||||||
}
|
|
||||||
}, [editor, setActiveBlocksuiteEditor]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Editor
|
<Editor
|
||||||
className={clsx(styles.editor, {
|
className={clsx(styles.editor, {
|
||||||
@@ -149,7 +132,6 @@ const PageDetailEditorMain = memo(function PageDetailEditorMain({
|
|||||||
onModeChange={setEditorMode}
|
onModeChange={setEditorMode}
|
||||||
defaultSelectedBlockId={blockId}
|
defaultSelectedBlockId={blockId}
|
||||||
onLoadEditor={onLoadEditor}
|
onLoadEditor={onLoadEditor}
|
||||||
ref={editorRef}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user