From bf239b14769864c549c043a34842340ee70ee25a Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 1 Feb 2022 14:01:50 +0100 Subject: [PATCH] refactoring --- admin/src/pages/Creation.vue | 61 +++++++++++++++++------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/admin/src/pages/Creation.vue b/admin/src/pages/Creation.vue index 68005d815..28549212e 100644 --- a/admin/src/pages/Creation.vue +++ b/admin/src/pages/Creation.vue @@ -28,7 +28,7 @@ -
+
{{ $t('multiple_creation_text') }}
@@ -104,7 +104,7 @@ export default { { key: 'bookmark', label: this.$t('remove') }, ], itemsList: [], - itemsMassCreationReverse: [], + itemsMassCreation: this.$store.state.userSelectedInMassCreation, radioSelectedMass: '', criteria: '', creation: [null, null, null], @@ -113,7 +113,7 @@ export default { perPage: 25, } }, - async created() { + async mounted() { await this.getUsers() }, methods: { @@ -136,51 +136,48 @@ export default { showDetails: false, } }) - this.updateItem(this.$store.state.userSelectedInMassCreation, 'mounted') + if (this.itemsMassCreation !== []) { + const selectedIndices = this.itemsMassCreation.map((item) => item.userId) + this.itemsList = this.itemsList.filter((item) => !selectedIndices.includes(item.userId)) + } }) .catch((error) => { this.$toasted.error(error.message) }) }, - updateItem(e, event) { - let index = 0 - let findArr = {} - const letItemList = this.$store.state.userSelectedInMassCreation - + updateItem(selectedItem, event) { switch (event) { case 'push': - findArr = this.itemsList.find((item) => e.userId === item.userId) - index = this.itemsList.indexOf(findArr) - this.itemsList.splice(index, 1) - letItemList.push(findArr) + this.itemsMassCreation.push( + this.itemsList.find((item) => selectedItem.userId === item.userId), + ) + this.itemsList = this.itemsList.filter((item) => selectedItem.userId !== item.userId) break case 'remove': - findArr = letItemList.find((item) => e.userId === item.userId) - index = letItemList.indexOf(findArr) - letItemList.splice(index, 1) - this.itemsList.push(findArr) - break - case 'mounted': - if (this.$store.state.userSelectedInMassCreation === []) return - letItemList.forEach((value, key) => { - findArr = this.itemsList.find((item) => value.userId === item.userId) - index = this.itemsList.indexOf(findArr) - this.itemsList.splice(index, 1) - }) + this.itemsList.push( + this.itemsMassCreation.find((item) => selectedItem.userId === item.userId), + ) + this.itemsMassCreation = this.itemsMassCreation.filter( + (item) => selectedItem.userId !== item.userId, + ) break default: throw new Error(event) } - this.lala = letItemList - this.itemsMassCreationReverse = letItemList - this.itemsMassCreationReverse.reverse() - this.$store.commit('setUserSelectedInMassCreation', letItemList) + this.$store.commit('setUserSelectedInMassCreation', this.itemsMassCreation) }, removeAllBookmark() { - this.$store.commit('setUserSelectedInMassCreation', []) + this.itemsMassCreation = [] + this.$store.commit('setUserSelectedInMassCreation', this.itemsMassCreation) this.getUsers() }, }, + computed: { + itemsMassCreationReverse() { + const array = this.itemsMassCreation + return array.reverse() + }, + }, watch: { currentPage() { this.getUsers()