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: implement get tag and get tags
thecodrr249a9e70f032
diff --git a/packages/core/__tests__/database.test.js b/packages/core/__tests__/database.test.jsindex 21d62b812..eae50bfcd 100644--- a/packages/core/__tests__/database.test.js+++ b/packages/core/__tests__/database.test.js@@ -203,6 +203,22 @@ test("note with text longer than 150 characters should have ... in the headline"expect(note.headline.includes("...")).toBe(true);}));+test("get tags", () =>+ noteTest({+ ...TEST_NOTE,+ tags: ["new", "tag", "goes", "here"]+ }).then(async ({ db }) => {+ expect(db.getTags().length).toBeGreaterThan(0);+ }));++test("get notes in tag", () =>+ noteTest({+ ...TEST_NOTE,+ tags: ["new", "tag", "goes", "here"]+ }).then(async ({ db }) => {+ expect(db.getTag("tag")[0].tags.includes("tag")).toBe(true);+ }));+test("get favorites", () =>noteTest({pinned: true,diff --git a/packages/core/api/database.js b/packages/core/api/database.jsindex 7d6687b65..3975d66be 100644--- a/packages/core/api/database.js+++ b/packages/core/api/database.js@@ -74,6 +74,10 @@ class Database {return tfun.filter(".pinned == true")(this.getNotes());}+ getTag(tag) {+ return tfun.filter(`.tags.includes('${tag}')`)(this.getNotes());+ }+/*** @param {string} by One from 'abc', 'month', 'year' or 'week'. Leave it empty for default grouping.* @param {boolean} special Should only be used in the React app.@@ -157,10 +161,13 @@ class Database {if (oldNote) {note.colors = setManipulator.union(oldNote.colors, note.colors);- await this.updateTags(setManipulator.complement(note.tags, oldNote.tags));+ await updateTags.call(+ this,+ setManipulator.complement(note.tags, oldNote.tags)+ );note.tags = setManipulator.union(oldNote.tags, note.tags);} else {- await this.updateTags(note.tags);+ await updateTags.call(this, note.tags);}this.notes[timestamp] = note;@@ -168,18 +175,6 @@ class Database {return timestamp;}- async updateTags(tags) {- for (let tag of tags) {- if (!tag || tag.trim().length <= 0) continue;- let oldCount = this.tags[tag] ? this.tags[tag].count : 0;- this.tags[tag] = {- title: tag,- count: oldCount + 1- };- }- await this.storage.write(KEYS.tags, this[KEYS.tags]);- }-pinItem(type, id) {return editItem.call(this, type, id, "pinned");}@@ -421,6 +416,10 @@ class Database {getUser() {return this.user;}++ getTags() {+ return extractValues(this.tags);+ }}export default Database;@@ -589,3 +588,15 @@ function getNoteContent(note) {delta: note.content.delta};}++async function updateTags(tags) {+ for (let tag of tags) {+ if (!tag || tag.trim().length <= 0) continue;+ let oldCount = this.tags[tag] ? this.tags[tag].count : 0;+ this.tags[tag] = {+ title: tag,+ count: oldCount + 1+ };+ }+ await this.storage.write(KEYS.tags, this[KEYS.tags]);+}