mobile: improve note saving reliability &

performance
This commit is contained in:
ammarahm-ed
2023-04-01 16:17:31 +05:00
committed by Ammar Ahmed
parent d838c2e8ad
commit ff84ee2d42

View File

@@ -239,7 +239,8 @@ export const useEditor = (
if (
useEditorStore.getState().currentEditingNote !== id &&
isDefaultEditor
isDefaultEditor &&
state.current.currentlyEditing
) {
setTimeout(() => {
id && useEditorStore.getState().setCurrentlyEditingNote(id);
@@ -505,17 +506,22 @@ export const useEditor = (
noteId: currentNote.current?.id as string
};
}
const noteIdFromSessionId =
!sessionIdRef.current || sessionIdRef.current.startsWith("session")
? null
: sessionIdRef.current.split("_")[0];
const noteId = currentNote.current?.id || noteIdFromSessionId;
const params = {
title,
data: content,
type: "tiptap",
sessionId,
id: currentNote.current?.id,
id: noteId,
sessionHistoryId: sessionHistoryId.current
};
withTimer(
currentNote.current?.id || "newnote",
noteId || "newnote",
() => {
if (
currentNote.current &&
@@ -530,7 +536,7 @@ export const useEditor = (
}
saveNote(params);
},
500
150
);
},
[sessionId, withTimer, onChange, saveNote]