Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

web: fix editor title not changing on realtime sync

Abdullah Atta8b1b569fee58
diff --git a/apps/web/src/components/editor/title-box.tsx b/apps/web/src/components/editor/title-box.tsx
index b4957e3dd..27f728efb 100644
--- a/apps/web/src/components/editor/title-box.tsx
+++ b/apps/web/src/components/editor/title-box.tsx
@@ -27,6 +27,7 @@ import { useEditorConfig } from "./manager";
import { getFontById } from "@notesnook/editor";
import { replaceDateTime } from "@notesnook/editor/dist/extensions/date-time";
import { useStore as useSettingsStore } from "../../stores/setting-store";
+import { AppEventManager, AppEvents } from "../../common/app-events";
type TitleBoxProps = {
id: string;
@@ -79,27 +80,28 @@ function TitleBox(props: TitleBoxProps) {
updateFontSize(inputRef.current.value.length);
}, [isTablet, isMobile, updateFontSize]);
- // useEffect(() => {
- // const { unsubscribe } = AppEventManager.subscribe(
- // AppEvents.changeNoteTitle,
- // ({ preventSave, title }: { title: string; preventSave: boolean }) => {
- // if (!inputRef.current) return;
- // withSelectionPersist(
- // inputRef.current,
- // (input) => (input.value = title)
- // );
- // updateFontSize(title.length);
- // if (!preventSave) {
- // const { sessionId, id } = store.get().session;
- // debouncedOnTitleChange(sessionId, id, title);
- // }
- // }
- // );
-
- // return () => {
- // unsubscribe();
- // };
- // }, []);
+ useEffect(() => {
+ const { unsubscribe } = AppEventManager.subscribe(
+ AppEvents.changeNoteTitle,
+ ({ preventSave, title }: { title: string; preventSave: boolean }) => {
+ if (!inputRef.current) return;
+ withSelectionPersist(
+ inputRef.current,
+ (input) => (input.value = title)
+ );
+ updateFontSize(title.length);
+ if (!preventSave) {
+ const { activeSessionId } = useEditorStore.getState();
+ if (!activeSessionId) return;
+ debouncedOnTitleChange(activeSessionId, activeSessionId, title);
+ }
+ }
+ );
+
+ return () => {
+ unsubscribe();
+ };
+ }, [updateFontSize]);
return (
<Input