From 6577c54a362ff00e5b9b1498eb03a9a9ffae5b7a Mon Sep 17 00:00:00 2001 From: zak39 Date: Mon, 13 Jan 2025 17:24:53 +0100 Subject: [PATCH] refactor(vue): Use return early principle to count users This refactor makes the code easier to read by reducing nesting and improving clarity. --- src/AddUsersTabs.vue | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/AddUsersTabs.vue b/src/AddUsersTabs.vue index 818770c6..0fc7c838 100644 --- a/src/AddUsersTabs.vue +++ b/src/AddUsersTabs.vue @@ -172,22 +172,25 @@ export default { this.$emit('close-sidebar') const space = this.$store.state.spaces[this.$route.params.space] this.allSelectedUsers.forEach(user => { - if (this.$route.params.slug !== undefined) { - if (decodeURIComponent(this.$route.params.slug).startsWith('SPACE-U')) { - this.addUserFromUserGroup(user) - return - } - if (decodeURIComponent(this.$route.params.slug).startsWith('SPACE-GE')) { - this.addUserFromManagerGroup(user, space) - return - } - if (Object.keys(space.users).includes(user.uid) && decodeURIComponent(this.$route.params.slug).startsWith('SPACE-G-')) { - this.addExistingUserFromSubgroup(user) - } else { - this.addNewUserFromSubgroup(user, space) - } - } else { + if (this.$route.params.slug === undefined) { this.addUserFromWorkspace(user, space) + return + } + + if (decodeURIComponent(this.$route.params.slug).startsWith('SPACE-U')) { + this.addUserFromUserGroup(user) + return + } + + if (decodeURIComponent(this.$route.params.slug).startsWith('SPACE-GE')) { + this.addUserFromManagerGroup(user, space) + return + } + + if (Object.keys(space.users).includes(user.uid) && decodeURIComponent(this.$route.params.slug).startsWith('SPACE-G-')) { + this.addExistingUserFromSubgroup(user) + } else { + this.addNewUserFromSubgroup(user, space) } }) },