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: topics not being edited
thecodrrb505991cd6a2
diff --git a/packages/core/__tests__/topics.test.js b/packages/core/__tests__/topics.test.jsindex 65fcefccb..393a8b01a 100644--- a/packages/core/__tests__/topics.test.js+++ b/packages/core/__tests__/topics.test.js@@ -21,7 +21,7 @@ test("add topic to notebook", () =>expect(topics.all.findIndex((v) => v.title === "Home")).toBeGreaterThan(-1);}));-test("update topic", () =>+test("add note to topic", () =>notebookTest().then(async ({ db, id }) => {let topics = db.notebooks.notebook(id).topics;await topics.add("Home");@@ -31,15 +31,20 @@ test("update topic", () =>expect(topics.all.find((v) => v.title === "Home").notes.length).toBe(1);}));-test("edit topic title", () =>+test.only("edit topic title", () =>notebookTest().then(async ({ db, id }) => {let topics = db.notebooks.notebook(id).topics;+await topics.add("Home");+let topic = topics.topic("Home");- expect(topics.all.length).toBeGreaterThan(1);++ expect(topics.all.length).toBe(3);+await topics.add({ id: topic._topic.id, title: "Hello22" });- expect(topics.all.length).toBeGreaterThan(1);- expect(topics.topic("Hello22")._topic.title).toBe("Hello22");++ expect(topics.all.length).toBe(3);+ expect(topics.topic(topic._topic.id)._topic.title).toBe("Hello22");}));test("duplicate topic to notebook should not be added", () =>diff --git a/packages/core/collections/topics.js b/packages/core/collections/topics.jsindex 842cc7459..cba32f675 100644--- a/packages/core/collections/topics.js+++ b/packages/core/collections/topics.js@@ -21,14 +21,14 @@ export default class Topics {);}- _dedupe(source) {+ /* _dedupe(source) {let length = source.length,seen = new Map();for (let index = 0; index < length; index++) {let value = source[index];if (value.id) {- seen.set(value.title, {- ...seen.get(value.title),+ seen.set(value.id, {+ ...seen.get(value.id),...value,});continue;@@ -38,19 +38,33 @@ export default class Topics {seen.set(title, value);}return seen;- }+ } */async add(...topics) {let notebook = qclone(this._db.notebooks.notebook(this._notebookId).data);let allTopics = [...notebook.topics, ...topics];- const unique = this._dedupe(allTopics);notebook.topics = [];notebook.totalNotes = 0;- unique.forEach((t) => {+ allTopics.forEach((t) => {let topic = makeTopic(t, this._notebookId);- notebook.topics.push(topic);++ if (notebook.topics.findIndex((_topic) => _topic.title === t) > -1)+ return;++ if (topic.title.length <= 0) return;++ let index = notebook.topics.findIndex((t) => t.id === topic.id);+ if (index > -1) {+ notebook.topics[index] = {+ ...notebook.topics[index],+ ...topic,+ };+ } else {+ notebook.topics.push(topic);+ }+notebook.totalNotes += topic.totalNotes;});@@ -99,7 +113,7 @@ function makeTopic(topic, notebookId) {type: "topic",id: id(), //topic,notebookId,- title: topic,+ title: topic.trim(),dateCreated: Date.now(),dateEdited: Date.now(),totalNotes: 0,