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: allow multiple notes/notebooks to be favorited & moved
thecodrrc1a13ed93a83
diff --git a/packages/core/__tests__/database.test.js b/packages/core/__tests__/database.test.jsindex 0a3fb3448..ceb2816cd 100644--- a/packages/core/__tests__/database.test.js+++ b/packages/core/__tests__/database.test.js@@ -311,12 +311,13 @@ test("move note", async () =>await db.addNoteToTopic(notebook1, "Home", timestamp);setTimeout(async () => {let notebook2 = await db.addNotebook(TEST_NOTEBOOK2);- let res = await db.moveNote(- timestamp,+ await db.moveNotes({ id: notebook1, topic: "Home" },- { id: notebook2, topic: "Home2" }+ { id: notebook2, topic: "Home2" },+ timestamp);- expect(res).toBe(true);+ let note = db.getNote(timestamp);+ expect(note.notebook.id).toBe(notebook2);}, 1000);}));@@ -439,24 +440,19 @@ test("deletion of invalid topic from notebook should return false", () =>test("moving note with wrong id should throw", () =>databaseTest().then(async db => {- db.moveNote(0, undefined, undefined).catch(err =>+ db.moveNotes(undefined, undefined, 0).catch(err =>expect(err.message).toContain("Failed to move note."));}));test("moving note to non-existent notebook should return false", () =>databaseTest().then(async db => {- let res = await await db.moveNote(- 29,- { id: 2, topic: "2" },- { id: 5, topic: "123" }- );- expect(res).toBe(false);+ await db.moveNotes({ id: 2, topic: "2" }, { id: 5, topic: "123" }, 23);}));test("moving note to same notebook should throw", () =>databaseTest().then(async db => {- db.moveNote(29, { id: 2, topic: "2" }, { id: 2, topic: "2" }).catch(err =>+ db.moveNotes({ id: 2, topic: "2" }, { id: 2, topic: "2" }, 23).catch(err =>expect(err.message).toContain("Moving to the same notebook and topic is not possible.")@@ -528,13 +524,13 @@ test("pin notebook", () =>test("favorite note", () =>noteTest().then(async ({ db, timestamp }) => {- await db.favoriteNote(timestamp);+ await db.favoriteNotes(timestamp);expect(db.getNote(timestamp).favorite).toBe(true);}));test("favorite notebook", () =>notebookTest().then(async ({ db, timestamp }) => {- await db.favoriteNotebook(timestamp);+ await db.favoriteNotebooks(timestamp);expect(db.getNotebook(timestamp).favorite).toBe(true);}));diff --git a/packages/core/api/database.js b/packages/core/api/database.jsindex cc8b3630d..804decf49 100644--- a/packages/core/api/database.js+++ b/packages/core/api/database.js@@ -190,11 +190,11 @@ class Database {}pinNote(id) {- return editItem.call(this, "note", id, "pinned");+ return editItems.call(this, "note", "pinned", id);}- favoriteNote(id) {- return editItem.call(this, "note", id, "favorite");+ favoriteNotes(...ids) {+ return editItems.call(this, "note", "favorite", ids);}async deleteNotes(...noteIds) {@@ -308,11 +308,11 @@ class Database {}pinNotebook(id) {- return editItem.call(this, "notebook", id, "pinned");+ return editItems.call(this, "notebook", "pinned", id);}- favoriteNotebook(id) {- return editItem.call(this, "notebook", id, "favorite");+ favoriteNotebooks(...ids) {+ return editItems.call(this, "notebook", "favorite", ids);}addTopicToNotebook(notebookId, topic) {@@ -396,25 +396,25 @@ class Database {return await deleteItems.call(this, notebookIds, KEYS.notebooks);}- async moveNote(noteId, from, to) {- if (!noteId || !to || !to.id || !to.topic) {- throw new Error(`Error: Failed to move note.`);- }- if (!from.id && !from.topic) {- return await this.addNoteToTopic(to.id, to.topic, noteId);- } else {- if (from.id === to.id && from.topic === to.topic) {- throw new Error(- "Moving to the same notebook and topic is not possible."- );+ async moveNotes(from, to, ...noteIds) {+ for (let noteId of noteIds) {+ if (!noteId || !to || !to.id || !to.topic) {+ throw new Error(`Error: Failed to move note.`);}+ if (!from.id && !from.topic) {+ await this.addNoteToTopic(to.id, to.topic, noteId);+ } else {+ if (from.id === to.id && from.topic === to.topic) {+ throw new Error(+ "Moving to the same notebook and topic is not possible."+ );+ }- if (await this.deleteNoteFromTopic(from.id, from.topic, noteId)) {- return await this.addNoteToTopic(to.id, to.topic, noteId);+ if (await this.deleteNoteFromTopic(from.id, from.topic, noteId)) {+ await this.addNoteToTopic(to.id, to.topic, noteId);+ }}}-- return false;}async restoreItem(id) {@@ -561,10 +561,9 @@ function makeTopic(topic, notebookId) {};}-async function editItem(type, id, prop) {- switch (type) {- case "notebook":- case "note":+async function editItems(type, prop, ...ids) {+ if (type === "note" || type === "notebook") {+ for (let id of ids) {let col = type == "note" ? this.notes : this.notebooks;let func = type == "note" ? this.addNote : this.addNotebook;if (col[id] === undefined) {@@ -573,9 +572,9 @@ async function editItem(type, id, prop) {let state = col[id][prop];let edit = { [prop]: !state };await func.call(this, { ...col[id], ...edit });- break;- default:- throw new Error("Invalid type given to pinItem");+ }+ } else {+ throw new Error("Invalid type given to pinItem");}}