From 355ddf08d094e2772a80beb9d57769a9cb4f1c74 Mon Sep 17 00:00:00 2001 From: HerrHase Date: Sun, 16 Oct 2022 20:18:09 +0200 Subject: [PATCH] bugfix tags --- src/js/components/fields/tags.riot | 9 +++------ src/js/database/apps.js | 13 +++++++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/js/components/fields/tags.riot b/src/js/components/fields/tags.riot index 40c23b1..4849716 100644 --- a/src/js/components/fields/tags.riot +++ b/src/js/components/fields/tags.riot @@ -142,10 +142,8 @@ for (let i = 0; i < this.state.tags.length; i++) { if (value === this.state.tags[i]) { inArray = true - this.state.errors.push('Already added') - this.update() - + break } } @@ -153,14 +151,13 @@ // if value is not already in data and longer than zero chars if (inArray === false && value.length > 0) { this.state.tags.push(value) - this.update() - this.$('input').value = '' } else if (value.length === 0) { this.state.errors.push('Required!') - this.update() } + this.update() + // adding focus to input this.$('input').focus(); } diff --git a/src/js/database/apps.js b/src/js/database/apps.js index b18a77b..baa619c 100644 --- a/src/js/database/apps.js +++ b/src/js/database/apps.js @@ -109,7 +109,17 @@ class AppsDatabase extends DatabaseHandler { } return this.db.put(data) - .then((response) => { + .then(async (response) => { + + const tagsDatabase = new TagsDatabase() + + // if tags are in data update tags also in database + if (data.tags && data.tags.length > 0) { + tagsDatabase.update(data.tags) + } else { + await tagsDatabase.removeNotNeeded() + } + return this.findOneById(response._id) }).catch((error) => { @@ -251,7 +261,6 @@ class AppsDatabase extends DatabaseHandler { } return this.db.find(query).then(async (documents) => { - console.log(documents.docs) return documents.docs }).catch((error) => {