From 3ee5ea097b95e04a17133d0b53d7441215187f0f Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Mon, 11 Mar 2024 11:06:06 +0500 Subject: [PATCH] web: fix editor title not updating on creating a note --- apps/web/src/components/editor/title-box.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/web/src/components/editor/title-box.tsx b/apps/web/src/components/editor/title-box.tsx index a642e0793..b4957e3dd 100644 --- a/apps/web/src/components/editor/title-box.tsx +++ b/apps/web/src/components/editor/title-box.tsx @@ -37,6 +37,7 @@ function TitleBox(props: TitleBoxProps) { const { readonly, id } = props; const inputRef = useRef(null); // const id = useStore((store) => store.session.id); + const sessionType = useEditorStore((store) => store.getActiveSession()?.type); const isMobile = useMobile(); const isTablet = useTablet(); const { editorConfig } = useEditorConfig(); @@ -62,13 +63,16 @@ function TitleBox(props: TitleBoxProps) { useEffect(() => { const session = useEditorStore.getState().getSession(id); - if (!session || !("note" in session) || !session.note) return; + if (!session || !("note" in session) || !session.note || !inputRef.current) + return; const { title } = session.note; - if (!inputRef.current) return; - inputRef.current.value = title || ""; + withSelectionPersist( + inputRef.current, + (input) => (input.value = title || "") + ); updateFontSize(title?.length || 0); - }, [id, updateFontSize]); + }, [sessionType, id, updateFontSize]); useEffect(() => { if (!inputRef.current) return;