Skip to content

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

fix: properly handle dupes created when typing in editor (fixes streetwriters/notesnook#644 fixes streetwriters/notesnook#621 fixes streetwriters/notesnook#680)

thecodrr88d5d2257633
diff --git a/apps/web/src/stores/editor-store.js b/apps/web/src/stores/editor-store.js
index 1b6edb67f..9fd1668df 100644
--- a/apps/web/src/stores/editor-store.js
+++ b/apps/web/src/stores/editor-store.js
@@ -122,10 +122,10 @@ class EditorStore extends BaseStore {
saveSession = async (sessionId, session) => {
const currentSession = this.get().session;
if (currentSession.readonly && session.readonly !== false) return; // do not allow saving of readonly session
- if (currentSession.saveState === 0) return;
+ if (currentSession.saveState === 0 || (currentSession.id && !sessionId))
+ return;
this.setSaveState(0);
-
try {
const id = await this._getSaveFn()({ ...session, id: sessionId });
if (currentSession && currentSession.id !== sessionId)
@@ -134,6 +134,11 @@ class EditorStore extends BaseStore {
let note = db.notes.note(id)?.data;
if (!note) throw new Error("Note not saved.");
+ if (!sessionId) {
+ noteStore.setSelectedNote(id);
+ hashNavigate(`/notes/${id}/edit`, { replace: true, notify: false });
+ }
+
if (currentSession.context) {
const { type, value } = currentSession.context;
if (type === "topic") await db.notes.move(value, id);
@@ -167,15 +172,10 @@ class EditorStore extends BaseStore {
state.session.context = null;
state.session.id = note.id;
state.session.title = note.title;
- state.session.saveState = 1;
state.session.dateEdited = note.dateEdited;
state.session.attachmentsLength = attachments.length;
});
- if (!sessionId) {
- noteStore.setSelectedNote(id);
- hashNavigate(`/notes/${id}/edit`, { replace: true, notify: false });
- }
this.setSaveState(1);
} catch (err) {
this.setSaveState(-1);