From e2b958c3055ceda8e4ce99d01207662bc1a42654 Mon Sep 17 00:00:00 2001 From: Jake Fulmine Date: Mon, 22 Aug 2022 12:13:52 +0200 Subject: [PATCH] fix(dashboard): editing and backing out should not update the card --- dashboard/src/lib/group/Body.svelte | 4 ++-- dashboard/src/lib/group/Edit.svelte | 6 +++++- dashboard/src/lib/list/CardsList.svelte | 8 ++++---- dashboard/src/lib/list/List.svelte | 14 +++++++++++--- dashboard/src/lib/member/Body.svelte | 4 ++-- dashboard/src/lib/member/Edit.svelte | 8 ++++++-- 6 files changed, 30 insertions(+), 14 deletions(-) diff --git a/dashboard/src/lib/group/Body.svelte b/dashboard/src/lib/group/Body.svelte index dd7368bf..2d729392 100644 --- a/dashboard/src/lib/group/Body.svelte +++ b/dashboard/src/lib/group/Body.svelte @@ -143,9 +143,9 @@ {:else if editMode} - + {:else if memberMode} - + {/if} diff --git a/dashboard/src/lib/group/Edit.svelte b/dashboard/src/lib/group/Edit.svelte index 01cf4482..e87badb8 100644 --- a/dashboard/src/lib/group/Edit.svelte +++ b/dashboard/src/lib/group/Edit.svelte @@ -23,6 +23,10 @@ dispatch('deletion', group.id); } + function update(group: Group) { + dispatch('update', group); + } + async function submit() { let data = input; err = []; @@ -45,7 +49,7 @@ loading = true; try { let res = await api().groups(group.id).patch({data}); - group = {...group, ...res}; + update({...group, ...res}); err = []; success = true; loading = false; diff --git a/dashboard/src/lib/list/CardsList.svelte b/dashboard/src/lib/list/CardsList.svelte index b0d3dab2..b1d2137c 100644 --- a/dashboard/src/lib/list/CardsList.svelte +++ b/dashboard/src/lib/list/CardsList.svelte @@ -129,9 +129,9 @@ {#if itemType === "member"} - + {:else if itemType === "group"} - + {/if} @@ -161,9 +161,9 @@ {#if itemType === "member"} - + {:else if itemType === "group"} - + {/if} diff --git a/dashboard/src/lib/list/List.svelte b/dashboard/src/lib/list/List.svelte index 088a8c77..9319b2c9 100644 --- a/dashboard/src/lib/list/List.svelte +++ b/dashboard/src/lib/list/List.svelte @@ -96,12 +96,20 @@ function updateDelete(event: any) { if (itemType === "member") { members = members.filter(m => m.id !== event.detail); - list = members; } else if (itemType === "group") { groups = groups.filter(g => g.id !== event.detail); - list = groups; } } + + function update(event: any) { + console.log(event.detail); + if (itemType === "member") { + members = members.map(m => m.id === event.detail.id ? m = event.detail : m); + } else if (itemType === "group") { + groups = groups.map(g => g.id === event.detail.id ? g = event.detail : g); + } + } + @@ -131,6 +139,6 @@ {/if} {/if} - + {/if} diff --git a/dashboard/src/lib/member/Body.svelte b/dashboard/src/lib/member/Body.svelte index 568fa3fd..2c30d741 100644 --- a/dashboard/src/lib/member/Body.svelte +++ b/dashboard/src/lib/member/Body.svelte @@ -187,8 +187,8 @@ {/if} {:else if editMode} - + {:else if groupMode} - + {/if} diff --git a/dashboard/src/lib/member/Edit.svelte b/dashboard/src/lib/member/Edit.svelte index 058fbc5c..1e5e77d0 100644 --- a/dashboard/src/lib/member/Edit.svelte +++ b/dashboard/src/lib/member/Edit.svelte @@ -16,7 +16,7 @@ let err: string[] = []; let success = false; - let input: Member = member; + let input: Member = JSON.parse(JSON.stringify(member)); const dispatch = createEventDispatcher(); @@ -24,6 +24,10 @@ dispatch('deletion', member.id); } + function update(member: Member) { + dispatch('update', member); + } + async function submit() { let data = input; err = []; @@ -69,7 +73,7 @@ loading = true; try { let res = await api().members(member.id).patch({data}); - member = res; + update({...member, ...res}); success = true; } catch (error) { console.log(error);