Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

Throttle editor draft work on mobile

yomae41c1c0a2c34
diff --git a/apps/web/src/components/EditorPane.tsx b/apps/web/src/components/EditorPane.tsx
index f0dad7d7..e4cf8d99 100644
--- a/apps/web/src/components/EditorPane.tsx
+++ b/apps/web/src/components/EditorPane.tsx
@@ -442,6 +442,9 @@ export const EditorPane = ({
const draftPersistTimerRef = useRef<number | null>(null);
const pendingBackAfterSaveRef = useRef(false);
const toolbarRefreshFrameRef = useRef<number | null>(null);
+ const draftTitleRef = useRef("");
+ const draftTagsTextRef = useRef("");
+ const saveStateRef = useRef<"idle" | "saving" | "saved" | "queued" | "error" | "conflict">("idle");
useEffect(() => {
const mediaQuery = window.matchMedia(MOBILE_EDITOR_QUERY);
@@ -651,6 +654,10 @@ export const EditorPane = ({
imageCompressionEnabledRef.current = imageCompressionEnabled;
}, [imageCompressionEnabled]);
+ useEffect(() => {
+ saveStateRef.current = saveState;
+ }, [saveState]);
+
useEffect(() => {
editorRef.current = editor;
return () => {
@@ -806,6 +813,9 @@ export const EditorPane = ({
return;
}
+ draftTitleRef.current = nextTitle;
+ draftTagsTextRef.current = nextTagsText;
+
const writeDraft = () => {
const latestMemo = memoRef.current;
const latestEditor = editorRef.current;
@@ -816,21 +826,21 @@ export const EditorPane = ({
void localDb.drafts.put({
memoId: latestMemo.id,
- title: nextTitle,
- tagsText: nextTagsText,
+ title: draftTitleRef.current,
+ tagsText: draftTagsTextRef.current,
contentJson: latestEditor.getJSON() as TiptapDoc,
updatedAt: new Date().toISOString(),
});
};
if (draftPersistTimerRef.current !== null) {
- window.clearTimeout(draftPersistTimerRef.current);
+ return;
}
draftPersistTimerRef.current = window.setTimeout(() => {
draftPersistTimerRef.current = null;
writeDraft();
- }, 350);
+ }, 1500);
},
[tagsText, title]
);
@@ -850,7 +860,10 @@ export const EditorPane = ({
setDirtyVersion((version) => version + 1);
}
- setSaveState((current) => (current === "conflict" ? current : "idle"));
+ if (saveStateRef.current !== "idle") {
+ saveStateRef.current = "idle";
+ setSaveState("idle");
+ }
}, [noteSearchOpen, noteSearchQuery]);
const currentSnapshot = useCallback(() => {