web: fix invalid usage of sessionId as noteId

This commit is contained in:
Abdullah Atta
2025-02-24 11:53:41 +05:00
parent ea7afbe93e
commit a912a1a22e

View File

@@ -920,15 +920,14 @@ class EditorStore extends BaseStore<EditorStore> {
this.setSaveState(id, 0); this.setSaveState(id, 0);
try { try {
const sessionId = getSessionId(currentSession); const sessionId = getSessionId(currentSession);
const noteId = let noteId =
("note" in currentSession "note" in currentSession ? currentSession.note.id : partial.note?.id;
? currentSession.note.id
: partial.note?.id) || id;
if (isLockedSession(currentSession) && partial.content) { if (isLockedSession(currentSession) && partial.content) {
logger.debug("Saving locked content", { id }); if (!noteId) return;
logger.debug("Saving locked content", { noteId });
await db.vault.save({ noteId = await db.vault.save({
content: partial.content, content: partial.content,
sessionId, sessionId,
id: noteId id: noteId
@@ -936,10 +935,10 @@ class EditorStore extends BaseStore<EditorStore> {
} else { } else {
if (partial.content) if (partial.content)
logger.debug("Saving content", { logger.debug("Saving content", {
id, noteId,
length: partial.content.data.length length: partial.content.data.length
}); });
await db.notes.add({ noteId = await db.notes.add({
...partial.note, ...partial.note,
dateEdited: dateEdited:
partial.ignoreEdit && currentSession.type === "default" partial.ignoreEdit && currentSession.type === "default"
@@ -955,7 +954,7 @@ class EditorStore extends BaseStore<EditorStore> {
}); });
} }
const note = await db.notes.note(noteId); const note = noteId && (await db.notes.note(noteId));
if (!note) throw new Error("Note not saved."); if (!note) throw new Error("Note not saved.");
if (currentSession.type === "new") { if (currentSession.type === "new") {
@@ -963,16 +962,16 @@ class EditorStore extends BaseStore<EditorStore> {
if (context) { if (context) {
const { type } = context; const { type } = context;
if (type === "notebook") if (type === "notebook")
await db.notes.addToNotebook(context.id, noteId); await db.notes.addToNotebook(context.id, note.id);
else if (type === "color" || type === "tag") else if (type === "color" || type === "tag")
await db.relations.add( await db.relations.add(
{ type, id: context.id }, { type, id: context.id },
{ id, type: "note" } { id: note.id, type: "note" }
); );
} else { } else {
const defaultNotebook = db.settings.getDefaultNotebook(); const defaultNotebook = db.settings.getDefaultNotebook();
if (defaultNotebook) if (defaultNotebook)
await db.notes.addToNotebook(defaultNotebook, noteId); await db.notes.addToNotebook(defaultNotebook, note.id);
} }
} }