mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-19 19:16:29 +08:00
feat: add lifecycle hook in editor provider
This commit is contained in:
@@ -142,12 +142,8 @@ const HeaderRight = () => {
|
||||
};
|
||||
|
||||
export const Header = ({ children }: PropsWithChildren<{}>) => {
|
||||
const { pageList } = useEditor();
|
||||
|
||||
const [showWarning, setShowWarning] = useState(shouldShowWarning());
|
||||
const router = useRouter();
|
||||
const currentPageMeta = pageList.find(p => p.id === router.query.pageId);
|
||||
const isTrash = !!currentPageMeta?.trash;
|
||||
|
||||
return (
|
||||
<StyledHeaderContainer hasWarning={showWarning}>
|
||||
<BrowserWarning
|
||||
|
||||
@@ -18,18 +18,17 @@ export const PageHeader = () => {
|
||||
const [title, setTitle] = useState('');
|
||||
const [isHover, setIsHover] = useState(false);
|
||||
|
||||
const { editor } = useEditor();
|
||||
const { editor, onPropsUpdated } = useEditor();
|
||||
const { triggerQuickSearchModal } = useModal();
|
||||
|
||||
useEffect(() => {
|
||||
if (editor?.model) {
|
||||
setTitle(editor.model.title || 'Untitled');
|
||||
editor.model.propsUpdated.on(() => {
|
||||
setTitle(editor.model.title);
|
||||
});
|
||||
}
|
||||
return () => {
|
||||
editor?.model?.propsUpdated.dispose();
|
||||
};
|
||||
onPropsUpdated(editor => {
|
||||
setTitle(editor.model.title);
|
||||
});
|
||||
}, [onPropsUpdated]);
|
||||
|
||||
useEffect(() => {
|
||||
setTitle(editor?.model.title || 'Untitled');
|
||||
}, [editor]);
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user