diff --git a/resources/vue/components/courseware/CoursewareAccordionContainer.vue b/resources/vue/components/courseware/CoursewareAccordionContainer.vue index 7d9f7626232592442cc8d81d2ef5c2b83a776ea8..8b2c9880638e3465f29814ff052880b4175c9bc0 100755 --- a/resources/vue/components/courseware/CoursewareAccordionContainer.vue +++ b/resources/vue/components/courseware/CoursewareAccordionContainer.vue @@ -164,11 +164,15 @@ export default { const unallocated = new Set(this.blocks.map(({ id }) => id)); - sections.forEach(section => { + for (let section of sections) { section.locked = false; section.blocks = section.blocks.map((id) => view.blockById({id})).filter(Boolean); - section.blocks.forEach(({ id }) => unallocated.delete(id)); - }); + for (let sectionBlock of section.blocks) { + if (sectionBlock?.id && unallocated.has(sectionBlock.id)) { + unallocated.delete(sectionBlock.id); + } + } + } if (unallocated.size > 0) { this.unallocatedBlocks = [...unallocated].map((id) => view.blockById({ id })); @@ -247,9 +251,11 @@ export default { } }, watch: { - blocks() { - if (!this.showEdit) { - this.initCurrentData(); + blocks(newBlocks, oldBlocks) { + if (!this.showEdit && !this.checkSimpleArrayEquality(newBlocks, oldBlocks)) { + this.$nextTick(() => { + setTimeout(() => this.initCurrentData(), 250); + }); } } } diff --git a/resources/vue/components/courseware/CoursewareTabsContainer.vue b/resources/vue/components/courseware/CoursewareTabsContainer.vue index 15b3c87b574e01d2ddac04dcb5c657202c9dc4d1..de1d858f182d395fd8d165350c08807b0b00e859 100755 --- a/resources/vue/components/courseware/CoursewareTabsContainer.vue +++ b/resources/vue/components/courseware/CoursewareTabsContainer.vue @@ -181,11 +181,15 @@ export default { const unallocated = new Set(this.blocks.map(({ id }) => id)); - sections.forEach(section => { + for (let section of sections) { section.locked = false; - section.blocks = section.blocks.map((id) => view.blockById({id})).filter((a) => a); - section.blocks.forEach(({ id }) => unallocated.delete(id)); - }); + section.blocks = section.blocks.map((id) => view.blockById({id})).filter(Boolean); + for (let sectionBlock of section.blocks) { + if (sectionBlock?.id && unallocated.has(sectionBlock.id)) { + unallocated.delete(sectionBlock.id); + } + } + } if (unallocated.size > 0) { this.unallocatedBlocks = [...unallocated].map((id) => view.blockById({ id })); @@ -265,9 +269,11 @@ export default { } }, watch: { - blocks() { - if (!this.showEdit) { - this.initCurrentData(); + blocks(newBlocks, oldBlocks) { + if (!this.showEdit && !this.checkSimpleArrayEquality(newBlocks, oldBlocks)) { + this.$nextTick(() => { + setTimeout(() => this.initCurrentData(), 250); + }); } } } diff --git a/resources/vue/mixins/courseware/container.js b/resources/vue/mixins/courseware/container.js index fac1ea604ef1d16bf91a1ffc9d19f012c92c3ec8..075137514adb1c988b469390e1be3c54ea0fad51 100755 --- a/resources/vue/mixins/courseware/container.js +++ b/resources/vue/mixins/courseware/container.js @@ -7,6 +7,13 @@ const containerMixin = { created: function () { this.pluginManager.registerComponentsLocally(this); }, + methods: { + checkSimpleArrayEquality(firstSet, secondSet) { + return Array.isArray(firstSet) && Array.isArray(secondSet) && + firstSet.length === secondSet.length && + firstSet.every((val, index) => val === secondSet[index]); + } + } }; export default containerMixin;