A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
fix: noteId not being removed from color or deleting
thecodrr220827000913
diff --git a/packages/core/__tests__/backup.test.js b/packages/core/__tests__/backup.test.jsindex 0b0dcd09c..f946bb6a8 100644--- a/packages/core/__tests__/backup.test.js+++ b/packages/core/__tests__/backup.test.js@@ -111,8 +111,6 @@ describe.each([verifyIndex(data, db, "notebooks", "notebooks");verifyIndex(data, db, "delta", "content");verifyIndex(data, db, "content", "content");- verifyIndex(data, db, "tags", "tags");- verifyIndex(data, db, "colors", "colors");verifyIndex(data, db, "trash", "trash");});});diff --git a/packages/core/collections/notes.js b/packages/core/collections/notes.jsindex 3f3d83816..4bc9c1f52 100644--- a/packages/core/collections/notes.js+++ b/packages/core/collections/notes.js@@ -223,8 +223,8 @@ export default class Notes extends Collection {async _delete(moveToTrash = true, ...ids) {for (let id of ids) {let item = this.note(id);- const itemData = qclone(item.data);if (!item) continue;+ const itemData = qclone(item.data);if (item.notebooks) {for (let notebook of item.notebooks) {for (let topic of notebook.topics) {@@ -238,8 +238,8 @@ export default class Notes extends Collection {for (let tag of item.tags) {await this._db.tags.remove(tag, id);}- if (item.color) {- await this._db.colors.remove(item.color, id);+ if (item.data.color) {+ await this._db.colors.remove(item.data.color, id);}await this._collection.removeItem(id);if (moveToTrash) await this._db.trash.add(itemData);diff --git a/packages/core/collections/tags.js b/packages/core/collections/tags.jsindex 034711134..1a9179e32 100644--- a/packages/core/collections/tags.js+++ b/packages/core/collections/tags.js@@ -10,37 +10,9 @@ export default class Tags extends Collection {return tagItem;}- async merge(tag) {- if (!tag) return;- if (tag.deleted) {- await this._collection.addItem(tag);- return;- }- const oldTag = this.all.find(- (t) => t.id === tag.id || t.title === tag.title- );-- if (!oldTag) return await this._collection.addItem(tag);-- const deletedIds = set.union(oldTag.deletedIds, tag.deletedIds);- const noteIds = set.difference(- set.union(oldTag.noteIds, tag.noteIds),- deletedIds- );-- const dateEdited =- tag.dateEdited > oldTag.dateEdited ? tag.dateEdited : oldTag.dateEdited;- tag = {- ...oldTag,- noteIds,- dateEdited,- deletedIds,- };- await this._collection.addItem(tag);- }-async add(tagId, noteId) {- if (!tagId || !noteId) return;+ if (!tagId || !noteId) new Error("tagId and noteId cannot be falsy.");+let tag = this.all.find((t) => t.id === tagId || t.title === tagId) || {title: tagId,};@@ -50,13 +22,11 @@ export default class Tags extends Collection {if (notes.find((id) => id === noteId)) return id;- let deletedIds = tag.deletedIds || [];tag = {type: "tag",id,title: tag.title,noteIds: [...notes, noteId],- deletedIds,};await this._collection.addItem(tag);@@ -72,14 +42,14 @@ export default class Tags extends Collection {}async remove(tagTitle, noteId) {- if (!tagTitle || !noteId) return;+ if (!tagTitle || !noteId) new Error("tagTitle and noteId cannot be falsy.");let tag = this.all.find((t) => t.title === tagTitle);- if (!tag) return;+ if (!tag) throw new Error(`No tag with title "${tagTitle}" found.`);tag = qclone(tag);const noteIndex = tag.noteIds.indexOf(noteId);- if (noteIndex <= -1) return;+ if (noteIndex <= -1)+ throw new Error(`No note of id "${noteId}" exists in this tag.`);tag.noteIds.splice(noteIndex, 1);- tag.deletedIds.push(noteId);if (tag.noteIds.length > 0) await this._collection.addItem(tag);else await this._collection.removeItem(tag.id);}diff --git a/packages/core/database/backup.js b/packages/core/database/backup.jsindex 9d59005f2..f09b891bd 100644--- a/packages/core/database/backup.js+++ b/packages/core/database/backup.js@@ -137,14 +137,6 @@ export default class Backup {index: data["notebooks"],dbCollection: this._db.notebooks,},- {- index: data["tags"],- dbCollection: this._db.tags,- },- {- index: data["colors"],- dbCollection: this._db.colors,- },{index: data["trash"],dbCollection: this._db.trash,diff --git a/packages/core/models/note.js b/packages/core/models/note.jsindex 3092d8d61..7b869ded6 100644--- a/packages/core/models/note.js+++ b/packages/core/models/note.js@@ -94,6 +94,7 @@ export default class Note {}async uncolor() {+ if (!this._note.color) return;await this._db.colors.remove(this._note.color, this._note.id);await this._db.notes._collection.addItem({...this._note,