fix: do not add duplicate colors/tags

This commit is contained in:
thecodrr
2019-12-21 18:38:18 +05:00
parent b3e426f171
commit 7158b1b2e4

View File

@@ -131,6 +131,21 @@ class Database {
.split(" ")
.slice(0, 3)
.join(" ");
//if note exists
if (this.notes[timestamp] !== undefined) {
let oldNote = this.notes[timestamp];
//if we are having new colors
if (oldNote.colors !== note.colors) {
note.colors = mergeDedupe(oldNote.colors, note.colors);
}
//if we are having new tags
//TODO add new tags to the tags collection...
if (oldNote.tags !== note.tags) {
note.tags = mergeDedupe(oldNote.tags, note.tags);
}
}
this.notes[timestamp] = {
type: "note",
title,
@@ -504,3 +519,7 @@ async function editItem(type, id, edit) {
throw new Error("Invalid type given to pinItem");
}
}
function mergeDedupe(arr) {
return [...new Set([].concat(...arr))];
}