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
feat(BREAKING): note.colors -> note.color
thecodrr0a949e7d1057
diff --git a/packages/core/__tests__/tags.test.js b/packages/core/__tests__/tags.test.jsindex 6b9d09e91..9949f3b17 100644--- a/packages/core/__tests__/tags.test.js+++ b/packages/core/__tests__/tags.test.js@@ -4,17 +4,29 @@ beforeEach(async () => {StorageInterface.clear();});+function checkColorValue(note, value) {+ expect(note.data.color).toBe(value);+}++function checkTagValue(note, value) {+ expect(note.data.tags[0]).toBe(value);+}+describe.each([- ["tag", "untag", "tags", "tagged", ["hello", "tag"]],- ["color", "uncolor", "colors", "colored", ["red", "blue"]],-])("%s", (action, unaction, collection, filter, values) => {+ ["tag", "untag", "tagged", "hello"],+ ["color", "uncolor", "colored", "red"],+])("%s", (action, unaction, filter, value) => {+ let check = action === "tag" ? checkTagValue : checkColorValue;+ let collection = action === "tag" ? "tags" : "colors";+ let key = action === "tag" ? "tags" : "color";+test(`${action} a note`, () =>noteTest().then(async ({ db, id }) => {let note = db.notes.note(id);- await note[action](values[0]);+ await note[action](value);note = db.notes.note(id);- expect(note[collection][0]).toBe(values[0]);- expect(db[collection].all[0].title).toBe(values[0]);+ check(note, value);+ expect(db[collection].all[0].title).toBe(value);expect(db[collection].all[0].noteIds.length).toBe(1);}));@@ -22,40 +34,38 @@ describe.each([noteTest().then(async ({ db, id }) => {const id2 = await db.notes.add(TEST_NOTE);let note = db.notes.note(id);- await note[action](values[0]);+ await note[action](value);note = db.notes.note(id2);- await note[action](values[0]);- expect(db[collection].all[0].title).toBe(values[0]);+ await note[action](value);+ expect(db[collection].all[0].title).toBe(value);expect(db[collection].all[0].noteIds.length).toBe(2);}));test(`${unaction} from note`, () =>noteTest().then(async ({ db, id }) => {let note = db.notes.note(id);- await note[action](values[0]);+ await note[action](value);note = db.notes.note(id);- expect(note[collection][0]).toBe(values[0]);- expect(db[collection].all[0].title).toBe(values[0]);- await note[unaction](values[0]);+ check(note, value);+ await note[unaction](value);note = db.notes.note(id);- expect(note[collection].length).toBe(0);+ check(note, undefined);expect(db[collection].all.length).toBe(0);}));test(`get ${collection}`, () =>- noteTest({- ...TEST_NOTE,- [collection]: values,- }).then(async ({ db }) => {+ noteTest().then(async ({ db, id }) => {+ let note = db.notes.note(id);+ await note[action](value);expect(db[collection].all.length).toBeGreaterThan(0);}));test(`get notes in ${action}`, () =>- noteTest({- ...TEST_NOTE,- [collection]: values,- }).then(async ({ db }) => {- const tag = db[collection].all.find((v) => v.title === values[0]);- expect(db.notes[filter](tag.id)[0][collection]).toStrictEqual(values);+ noteTest().then(async ({ db, id }) => {+ let note = db.notes.note(id);+ await note[action](value);+ const tag = db[collection].all.find((v) => v.title === value);+ const filteredNotes = db.notes[filter](tag.id);+ check(db.notes.note(filteredNotes[0]), value);}));});diff --git a/packages/core/api/sync/__tests__/merger.test.js b/packages/core/api/sync/__tests__/merger.test.jsindex 00b48e5b9..191a01e2a 100644--- a/packages/core/api/sync/__tests__/merger.test.js+++ b/packages/core/api/sync/__tests__/merger.test.js@@ -87,7 +87,13 @@ describe.each(tests)(item.title = "Google";const result = await merger.merge({- [collection]: [{ id: item.id, ...(await getEncrypted(item)) }],+ [collection]: [+ {+ v: CURRENT_DATABASE_VERSION,+ id: item.id,+ ...(await getEncrypted(item)),+ },+ ],synced: false,},0diff --git a/packages/core/collections/notes.js b/packages/core/collections/notes.jsindex 597d29170..bdfa4533a 100644--- a/packages/core/collections/notes.js+++ b/packages/core/collections/notes.js@@ -67,7 +67,7 @@ export default class Notes extends Collection {pinned: !!note.pinned,locked: !!note.locked,notebooks: note.notebooks || undefined,- colors: note.colors || [],+ color: note.color,tags: note.tags || [],favorite: !!note.favorite,dateCreated: note.dateCreated,@@ -75,9 +75,7 @@ export default class Notes extends Collection {};if (!oldNote || oldNote.deleted) {- for (let color of note.colors) {- await this._db.colors.add(color, id);- }+ if (note.color) await this._db.colors.add(note.color, id);for (let tag of note.tags) {await this._db.tags.add(tag, id);@@ -212,8 +210,8 @@ export default class Notes extends Collection {for (let tag of item.tags) {await this._db.tags.remove(tag, id);}- for (let color of item.colors) {- await this._db.colors.remove(color, id);+ if (item.color) {+ await this._db.colors.remove(item.color, id);}await this._collection.removeItem(id);if (moveToTrash) await this._db.trash.add(item.data);diff --git a/packages/core/models/note.js b/packages/core/models/note.jsindex 151f1fe81..c462dd3b7 100644--- a/packages/core/models/note.js+++ b/packages/core/models/note.js@@ -85,11 +85,16 @@ export default class Note {async color(color) {if (!(await sendCheckUserStatusEvent(CHECK_IDS.noteColor))) return;- return await addTag.call(this, color, "colors");+ await this._db.colors.add(color, this._note.id);+ await this._db.notes._collection.addItem({ ...this._note, color });}- uncolor(color) {- return removeTag.call(this, color, "colors");+ async uncolor() {+ await this._db.colors.remove(this._note.color, this._note.id);+ await this._db.notes._collection.addItem({+ ...this._note,+ color: undefined,+ });}async tag(tag) {