From ce302e48fec41364e143ad7c04ebfda3d6f8a74a Mon Sep 17 00:00:00 2001 From: Dhruv Date: Wed, 23 Sep 2020 15:30:29 +0530 Subject: [PATCH] Fixed the uniquie ID issue on addition --- activities/Curriculum.activity/js/Settings.js | 12 ++++++------ activities/Vote.activity/js/Settings.js | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/activities/Curriculum.activity/js/Settings.js b/activities/Curriculum.activity/js/Settings.js index 40890eebd..0b3f29a2c 100644 --- a/activities/Curriculum.activity/js/Settings.js +++ b/activities/Curriculum.activity/js/Settings.js @@ -101,13 +101,13 @@ var CategorySettings = { }, addCategory: function() { - var nextId = this.categories.length; - this.category.id = nextId; + var maxId = this.categories.reduce((max, category) => max = Math.max(category.id, max), -1); + this.category.id = maxId + 1; this.categories.push(this.category); setTimeout(function () { content.scrollTop = content.scrollHeight; }, 250); - this.$set(this.user.skills, nextId, new Object()); + this.$set(this.user.skills, maxId + 1, new Object()); } } } @@ -239,13 +239,13 @@ var SkillSettings = { }, addSkill: function(catIndex) { - var nextId = this.categories[catIndex].skills.length; - this.skill.id = nextId; + var maxId = this.categories[catIndex].skills.reduce((max, skill) => max = Math.max(skill.id, max), -1); + this.skill.id = maxId + 1; this.categories[catIndex].skills.push(this.skill); setTimeout(function () { content.scrollTop = content.scrollHeight; }, 250); - this.$set(this.user.skills[this.categoryId], nextId, { + this.$set(this.user.skills[this.categoryId], maxId + 1, { acquired: 0, media: {} }); diff --git a/activities/Vote.activity/js/Settings.js b/activities/Vote.activity/js/Settings.js index 1dd54302f..ab7300a89 100644 --- a/activities/Vote.activity/js/Settings.js +++ b/activities/Vote.activity/js/Settings.js @@ -163,8 +163,8 @@ var PollSettings = { }, addPoll() { - var nextId = this.polls.length; - this.poll.id = nextId; + var maxId = this.polls.reduce((max, poll) => max = Math.max(poll.id, max), -1); + this.poll.id = maxId + 1; this.polls.push(this.poll); this.$emit('poll-added', this.poll.id); }