|
| 1 | +<!-- |
| 2 | + - SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors |
| 3 | + - SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | +--> |
| 5 | + |
| 6 | +<template> |
| 7 | + <AppContent :aria-label="t('contacts', 'Teams')"> |
| 8 | + <EmptyContent v-if="!circle && !userGroup" :name="t('contacts', 'Please select a team')"> |
| 9 | + <template #icon> |
| 10 | + <AccountGroup :size="20" /> |
| 11 | + </template> |
| 12 | + </EmptyContent> |
| 13 | + |
| 14 | + <EmptyContent v-else-if="loading" class="empty-content" :name="t('contacts', 'Loading team…')"> |
| 15 | + <template #icon> |
| 16 | + <IconLoading :size="20" /> |
| 17 | + </template> |
| 18 | + </EmptyContent> |
| 19 | + |
| 20 | + <UserGroupDetails v-else-if="userGroup" :user-group="userGroup" /> |
| 21 | + <CircleDetails v-else :circle="circle" /> |
| 22 | + </AppContent> |
| 23 | +</template> |
| 24 | + |
| 25 | +<script> |
| 26 | +import { showError } from '@nextcloud/dialogs' |
| 27 | +import { |
| 28 | + NcAppContent as AppContent, |
| 29 | + NcEmptyContent as EmptyContent, |
| 30 | + NcLoadingIcon as IconLoading, |
| 31 | +} from '@nextcloud/vue' |
| 32 | +import { mapStores } from 'pinia' |
| 33 | +import AccountGroup from 'vue-material-design-icons/AccountGroupOutline.vue' |
| 34 | +import CircleDetails from '../CircleDetails.vue' |
| 35 | +import UserGroupDetails from '../UserGroupDetails.vue' |
| 36 | +import IsMobileMixin from '../../mixins/IsMobileMixin.ts' |
| 37 | +import RouterMixin from '../../mixins/RouterMixin.js' |
| 38 | +import logger from '../../services/logger.js' |
| 39 | +import useUserGroupStore from '../../store/userGroup.ts' |
| 40 | +
|
| 41 | +export default { |
| 42 | + name: 'CircleContent', |
| 43 | +
|
| 44 | + components: { |
| 45 | + AppContent, |
| 46 | + CircleDetails, |
| 47 | + EmptyContent, |
| 48 | + AccountGroup, |
| 49 | + IconLoading, |
| 50 | + UserGroupDetails, |
| 51 | + }, |
| 52 | +
|
| 53 | + mixins: [IsMobileMixin, RouterMixin], |
| 54 | +
|
| 55 | + props: { |
| 56 | + loading: { |
| 57 | + type: Boolean, |
| 58 | + default: true, |
| 59 | + }, |
| 60 | + }, |
| 61 | +
|
| 62 | + data() { |
| 63 | + return { |
| 64 | + loadingList: false, |
| 65 | + } |
| 66 | + }, |
| 67 | +
|
| 68 | + computed: { |
| 69 | + // store variables |
| 70 | + circles() { |
| 71 | + return this.$store.getters.getCircles |
| 72 | + }, |
| 73 | +
|
| 74 | + circle() { |
| 75 | + return this.$store.getters.getCircle(this.selectedCircle) |
| 76 | + }, |
| 77 | +
|
| 78 | + userGroup() { |
| 79 | + return this.userGroupStore.getUserGroup(this.selectedUserGroup) |
| 80 | + }, |
| 81 | +
|
| 82 | + members() { |
| 83 | + return Object.values(this.circle?.members || []) |
| 84 | + }, |
| 85 | +
|
| 86 | + /** |
| 87 | + * Is the current circle empty |
| 88 | + * |
| 89 | + * @return {boolean} |
| 90 | + */ |
| 91 | + isEmptyCircle() { |
| 92 | + return this.members.length === 0 |
| 93 | + }, |
| 94 | +
|
| 95 | + ...mapStores(useUserGroupStore), |
| 96 | + }, |
| 97 | +
|
| 98 | + watch: { |
| 99 | + circle(newCircle) { |
| 100 | + if (newCircle?.id) { |
| 101 | + this.fetchCircleMembers(newCircle.id) |
| 102 | + } |
| 103 | + }, |
| 104 | +
|
| 105 | + userGroup(newUserGroup) { |
| 106 | + if (newUserGroup?.id) { |
| 107 | + this.fetchUserGroupMembers(newUserGroup.id) |
| 108 | + } |
| 109 | + }, |
| 110 | + }, |
| 111 | +
|
| 112 | + beforeMount() { |
| 113 | + if (this.circle?.id) { |
| 114 | + this.fetchCircleMembers(this.circle.id) |
| 115 | + } |
| 116 | +
|
| 117 | + if (this.userGroup?.id) { |
| 118 | + this.fetchUserGroupMembers(this.userGroup.id) |
| 119 | + } |
| 120 | + }, |
| 121 | +
|
| 122 | + methods: { |
| 123 | + async fetchCircleMembers(circleId) { |
| 124 | + this.loadingList = true |
| 125 | + this.logger.debug('Fetching members for', { circleId }) |
| 126 | +
|
| 127 | + try { |
| 128 | + await this.$store.dispatch('getCircleMembers', circleId) |
| 129 | + } catch (error) { |
| 130 | + logger.error(error) |
| 131 | + showError(t('contacts', 'There was an error fetching the member list')) |
| 132 | + } finally { |
| 133 | + this.loadingList = false |
| 134 | + } |
| 135 | + }, |
| 136 | +
|
| 137 | + async fetchUserGroupMembers(userGroupId) { |
| 138 | + this.loadingList = true |
| 139 | +
|
| 140 | + try { |
| 141 | + await this.userGroupStore.getUserGroupMembers(userGroupId) |
| 142 | + } catch (error) { |
| 143 | + logger.error(error) |
| 144 | + showError(t('contacts', 'There was an error fetching the member list')) |
| 145 | + } finally { |
| 146 | + this.loadingList = false |
| 147 | + } |
| 148 | + }, |
| 149 | + }, |
| 150 | +} |
| 151 | +</script> |
| 152 | +
|
| 153 | +<style lang="scss" scoped> |
| 154 | +// TODO: replace my button component when available |
| 155 | +button { |
| 156 | + height: 44px; |
| 157 | + display: flex; |
| 158 | + justify-content: center; |
| 159 | + align-items: center; |
| 160 | + span { |
| 161 | + margin-inline-end: 10px; |
| 162 | + } |
| 163 | +} |
| 164 | +
|
| 165 | +.empty-content { |
| 166 | + height: 100%; |
| 167 | +} |
| 168 | +</style> |
0 commit comments