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); }