mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
feat: implement get tag and get tags
This commit is contained in:
@@ -203,6 +203,22 @@ test("note with text longer than 150 characters should have ... in the headline"
|
|||||||
expect(note.headline.includes("...")).toBe(true);
|
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", () =>
|
test("get favorites", () =>
|
||||||
noteTest({
|
noteTest({
|
||||||
pinned: true,
|
pinned: true,
|
||||||
|
|||||||
@@ -74,6 +74,10 @@ class Database {
|
|||||||
return tfun.filter(".pinned == true")(this.getNotes());
|
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 {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.
|
* @param {boolean} special Should only be used in the React app.
|
||||||
@@ -157,10 +161,13 @@ class Database {
|
|||||||
|
|
||||||
if (oldNote) {
|
if (oldNote) {
|
||||||
note.colors = setManipulator.union(oldNote.colors, note.colors);
|
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);
|
note.tags = setManipulator.union(oldNote.tags, note.tags);
|
||||||
} else {
|
} else {
|
||||||
await this.updateTags(note.tags);
|
await updateTags.call(this, note.tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.notes[timestamp] = note;
|
this.notes[timestamp] = note;
|
||||||
@@ -168,18 +175,6 @@ class Database {
|
|||||||
return timestamp;
|
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) {
|
pinItem(type, id) {
|
||||||
return editItem.call(this, type, id, "pinned");
|
return editItem.call(this, type, id, "pinned");
|
||||||
}
|
}
|
||||||
@@ -421,6 +416,10 @@ class Database {
|
|||||||
getUser() {
|
getUser() {
|
||||||
return this.user;
|
return this.user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getTags() {
|
||||||
|
return extractValues(this.tags);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Database;
|
export default Database;
|
||||||
@@ -589,3 +588,15 @@ function getNoteContent(note) {
|
|||||||
delta: note.content.delta
|
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]);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user