From 7158b1b2e42677c39f115e1d178be5d001da0569 Mon Sep 17 00:00:00 2001 From: thecodrr Date: Sat, 21 Dec 2019 18:38:18 +0500 Subject: [PATCH] fix: do not add duplicate colors/tags --- packages/core/api/database.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/core/api/database.js b/packages/core/api/database.js index 54b92a909..6e1458789 100644 --- a/packages/core/api/database.js +++ b/packages/core/api/database.js @@ -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))]; +}