diff --git a/src/lib/group/MemberEdit.svelte b/src/lib/group/MemberEdit.svelte index 0d2caf59..a1dc8673 100644 --- a/src/lib/group/MemberEdit.svelte +++ b/src/lib/group/MemberEdit.svelte @@ -1,7 +1,7 @@ + const dispatch = createEventDispatcher(); + function update() { + dispatch("update", group) + } + + const api = new PKAPI(); + + async function submitAdd() { + let data = membersToBeAdded; + try { + loading = true; + await api.postGroupMembers({token: localStorage.getItem("pk-token"), id: group.id, data: data, removing: false}); + data.forEach(member => group.members.push(member)); + update(); + err = null; + membersToBeAdded = []; + loading = false; + } catch (error) { + console.log(error); + err = error.message; + loading = false; + } + } + + async function submitRemove() { + let data = membersToBeRemoved; + try { + loading = true; + await api.postGroupMembers({token: localStorage.getItem("pk-token"), id: group.id, data: data, removing: true}); + group.members = group.members.filter(m => !data.includes(m)); + update(); + err = null; + membersToBeRemoved = []; + loading = false; + } catch (error) { + console.log(error); + err = error.message; + loading = false; + } + } + + +{#if err} + {err} +{/if}
@@ -85,13 +130,19 @@ function memberListRenderer(item: any) {
Add Members
-

(this is nonfunctional at the moment)

+ {#if !loading && membersToBeAdded && membersToBeAdded.length > 0} + {:else} + + {/if}
Remove Members
-

(this is ALSO nonfunctional)

+ {#if !loading && membersToBeRemoved && membersToBeRemoved.length > 0} + {:else} + + {/if}
\ No newline at end of file diff --git a/src/lib/member/Body.svelte b/src/lib/member/Body.svelte index c10f73e1..c92e06fe 100644 --- a/src/lib/member/Body.svelte +++ b/src/lib/member/Body.svelte @@ -131,6 +131,6 @@ {:else if editMode} {:else if groupMode} - + {/if} \ No newline at end of file diff --git a/src/lib/member/GroupEdit.svelte b/src/lib/member/GroupEdit.svelte index 686a30fd..1832c5ec 100644 --- a/src/lib/member/GroupEdit.svelte +++ b/src/lib/member/GroupEdit.svelte @@ -1,7 +1,7 @@ + const dispatch = createEventDispatcher(); + function updateGroups() { + dispatch("updateGroups", groups); + } + + const api = new PKAPI(); + + async function submitAdd() { + let data = groupsToBeAdded; + try { + loading = true; + await api.postMemberGroups({token: localStorage.getItem("pk-token"), id: member.id, data: data, removing: false}); + groups.forEach(group => data.includes(group.uuid) && group.members.push(member.uuid)); + updateGroups(); + err = null; + groupsToBeAdded = []; + loading = false; + } catch (error) { + console.log(error); + err = error.message; + loading = false; + } + } + + async function submitRemove() { + let data = groupsToBeRemoved; + try { + loading = true; + await api.postMemberGroups({token: localStorage.getItem("pk-token"), id: member.id, data: data, removing: true}); + groups.forEach(group => {if (data.includes(group.uuid)) group.members = group.members.filter(m => m !== member.uuid)}); + updateGroups(); + err = null; + groupsToBeRemoved = []; + loading = false; + } catch (error) { + console.log(error); + err = error.message; + loading = false; + } + } + + +{#if err} + {err} +{/if}
@@ -86,13 +131,19 @@
Add to Groups
-

(this is nonfunctional at the moment)

+ {#if !loading && groupsToBeAdded && groupsToBeAdded.length > 0} + {:else} + + {/if}
Remove from Groups
-

(this is ALSO nonfunctional)

+ {#if !loading && groupsToBeRemoved && groupsToBeRemoved.length > 0} + {:else} + + {/if}
\ No newline at end of file