diff --git a/apps/client/src/widgets/note_title.tsx b/apps/client/src/widgets/note_title.tsx index bce3b289d..b3323fb1c 100644 --- a/apps/client/src/widgets/note_title.tsx +++ b/apps/client/src/widgets/note_title.tsx @@ -11,14 +11,14 @@ import branches from "../services/branches"; import { isIMEComposing } from "../services/shortcuts"; export default function NoteTitleWidget() { - const { note, noteId, componentId, viewScope, noteContext, parentComponent } = useNoteContext(); - const title = useNoteProperty(note, "title", componentId); + const { note, noteId, componentId, viewScope, noteContext, parentComponent } = useNoteContext(); + const title = useNoteProperty(note, "title", componentId); const isProtected = useNoteProperty(note, "isProtected"); const newTitle = useRef(""); - + const [ isReadOnly, setReadOnly ] = useState(false); - const [ navigationTitle, setNavigationTitle ] = useState(null); - + const [ navigationTitle, setNavigationTitle ] = useState(null); + // Manage read-only useEffect(() => { const isReadOnly = note === null @@ -34,7 +34,7 @@ export default function NoteTitleWidget() { if (isReadOnly) { noteContext?.getNavigationTitle().then(setNavigationTitle); } - }, [isReadOnly]); + }, [noteContext, isReadOnly]); // Save changes to title. const spacedUpdate = useSpacedUpdate(async () => { @@ -43,11 +43,11 @@ export default function NoteTitleWidget() { } protected_session_holder.touchProtectedSessionIfNecessary(note); await server.put(`notes/${noteId}/title`, { title: newTitle.current }, componentId); - }); + }); // Prevent user from navigating away if the spaced update is not done. useEffect(() => { - appContext.addBeforeUnloadListener(() => spacedUpdate.isAllSavedAndTriggerUpdate()); + appContext.addBeforeUnloadListener(() => spacedUpdate.isAllSavedAndTriggerUpdate()); }, []); useTriliumEvents([ "beforeNoteSwitch", "beforeNoteContextRemove" ], () => spacedUpdate.updateNowIfNecessary()); @@ -84,7 +84,7 @@ export default function NoteTitleWidget() { if (isIMEComposing(e)) { return; } - + // Focus on the note content when pressing enter. if (e.key === "Enter") { e.preventDefault();