Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions src/components/AppNavigation/CircleNavigationItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,7 @@ export default {

computed: {
memberCount() {
const count = Object.keys(this.circle?.members || []).length

// If member list is empty, let's try the population initial count
if (count === 0 && this.circle.population > 0) {
return this.circle.population
}

return count
return this.circle.populationInherited || 0
},
},
}
Expand Down
6 changes: 5 additions & 1 deletion src/models/circle.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ export default class Circle {
*/
set description(text: string)
/**
* Circle member count
* Circle direct member count (excluding nested circles)
*/
get population(): any
/**
* Circle total member count (direct + inherited from nested circles)
*/
get populationInherited(): any
/**
* Circle ini_initiator the current
* user info for this circle
Expand Down
9 changes: 8 additions & 1 deletion src/models/circle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,19 @@ export default class Circle {
}

/**
* Circle member count
* Circle direct member count (excluding nested circles)
*/
get population() {
return this._data.population
}

/**
* Circle total member count (direct + inherited from nested circles)
*/
get populationInherited() {
return this._data.populationInherited
}

// MEMBERSHIP -----------------------------------------
/**
* Circle ini_initiator the current
Expand Down
35 changes: 34 additions & 1 deletion src/store/circles.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ const mutations = {
setCircleSettings(state, { circleId, settings }) {
state.circles[circleId]._data.settings = settings
},

/**
* Update circle population count
*
* @param {object} state the store data
* @param {object} data destructuring object
* @param {string} data.circleId the circle to update the population
* @param {number} data.populationInherited the inherited population count
*/
updateCirclePopulationCount(state, { circleId, populationInherited }) {
state.circles[circleId]._data.populationInherited = populationInherited
},
}

const getters = {
Expand Down Expand Up @@ -178,6 +190,7 @@ const actions = {
const circle = new Circle(response)
context.commit('addCircle', circle)
logger.debug('Created circle', { circleName, circle })
context.dispatch('updateCirclesPopulationCount')
return circle
} catch (error) {
console.error(error)
Expand All @@ -197,12 +210,29 @@ const actions = {
await deleteCircle(circleId)
context.commit('deleteCircle', circle)
logger.debug('Deleted circle', { circleId })
context.dispatch('updateCirclesPopulationCount')
} catch (error) {
console.error(error)
showError(t('contacts', 'Unable to delete team {circleId}', circleId))
}
},

/**
* Update population count for all circles
*
* @param {object} context the store mutations Current context
*/
async updateCirclesPopulationCount(context) {
const circles = await getCircles()
circles.forEach((circle) => {
context.commit('updateCirclePopulationCount', {
circleId: circle.id,
populationInherited: circle.populationInherited,
})
})
logger.debug('Updated population count for all circles')
},

/**
* Add members to a circle
*
Expand All @@ -217,8 +247,9 @@ const actions = {
const results = await addMembers(circleId, selection)
const members = results.map((member) => new Member(member, circle))

logger.debug('Added members to circle', { circle, members })
context.commit('appendMembersToCircle', members)
logger.debug('Added members to circle', { circle, members })
context.dispatch('updateCirclesPopulationCount')

return members
},
Expand Down Expand Up @@ -250,6 +281,7 @@ const actions = {
// success, let's remove from store
context.commit('deleteMemberFromCircle', member)
logger.debug('Deleted member', { circleId, memberId })
context.dispatch('updateCirclesPopulationCount')
},

/**
Expand All @@ -267,6 +299,7 @@ const actions = {
const member = new Member(result, circle)

await context.commit('addMemberToCircle', { circleId, member })
context.dispatch('updateCirclesPopulationCount')
},

async editCircleSetting(context, { circleId, setting }) {
Expand Down
Loading