summaryrefslogtreecommitdiffstats
path: root/src/store
diff options
context:
space:
mode:
authorJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2021-03-10 09:12:52 +0100
committerJohn Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>2021-05-30 10:28:56 +0200
commit21c5e699ffa394c45094e898af0f5192cf239bee (patch)
treecfc68ae8ac5205500e01581367dc61badb8fab37 /src/store
parent0538d6a7cf0652a6f715e873f49fcc0b6094ad6d (diff)
Fix circle leave and visible/member checks
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'src/store')
-rw-r--r--src/store/circles.js32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/store/circles.js b/src/store/circles.js
index dc369e0f..900d6356 100644
--- a/src/store/circles.js
+++ b/src/store/circles.js
@@ -41,6 +41,9 @@ const mutations = {
* @param {Circle} circle the circle to add
*/
addCircle(state, circle) {
+ if (circle.constructor.name !== Circle.name) {
+ throw new Error('circle must be a Circle type')
+ }
Vue.set(state.circles, circle.id, circle)
},
@@ -51,23 +54,13 @@ const mutations = {
* @param {Circle} circle the circle to delete
*/
deleteCircle(state, circle) {
+ if (!(circle.id in state.circles)) {
+ console.warn('Skipping deletion of unknown circle', circle)
+ }
Vue.delete(state.circles, circle.id)
},
/**
- * Rename a circle
- *
- * @param {Object} state the store mutations
- * @param {Object} data destructuring object
- * @param {Circle} data.circle the circle to rename
- * @param {string} data.newName the new name of the addressbook
- */
- renameCircle(state, { circle, newName }) {
- circle = state.circles[circle.id]
- circle.displayName = newName
- },
-
- /**
* Append a list of members to a circle
* and remove duplicates
*
@@ -193,14 +186,21 @@ const actions = {
*
* @param {Object} context the store mutations Current context
* @param {Member} member the member to remove
- * @param {boolean} [leave=false] leave the circle instead of removing a member
+ * @param {boolean} [leave=false] leave the circle instead of removing the member
*/
async deleteMemberFromCircle(context, { member, leave = false }) {
- console.info(leave);
const circleId = member.circle.id
const memberId = member.id
+
if (leave) {
- await leaveCircle(circleId)
+ const circle = await leaveCircle(circleId)
+ member.circle.updateData(circle)
+
+ // If the circle is not visible, we remove it from the list
+ if (!member.circle.isVisible && !member.circle.isMember) {
+ await context.commit('deleteCircle', circle)
+ console.debug('Deleted circle', circleId, memberId)
+ }
} else {
await deleteMember(circleId, memberId)
}