Allow for editing groups for now

This commit is contained in:
Fulmine 2022-03-19 12:42:28 +01:00
parent bf413f2a26
commit e4142a9762
2 changed files with 22 additions and 5 deletions

View File

@ -103,8 +103,9 @@
{#if (group.banner && ((settings && settings.appearance.banner_bottom) || !settings))} {#if (group.banner && ((settings && settings.appearance.banner_bottom) || !settings))}
<img src={group.banner} alt="your system banner" class="w-100 mb-3 rounded" style="max-height: 12em; object-fit: cover"/> <img src={group.banner} alt="your system banner" class="w-100 mb-3 rounded" style="max-height: 12em; object-fit: cover"/>
{/if} {/if}
{#if !isPublic && isMainDash} {#if !isPublic}
<Button style="flex: 0" color="primary" on:click={() => editMode = true}>Edit</Button> <Button style="flex: 0" color="secondary" on:click={() => memberMode = true}>Members</Button> <Button style="flex: 0" color="primary" on:click={() => editMode = true}>Edit</Button>
{#if isMainDash}<Button style="flex: 0" color="secondary" on:click={() => memberMode = true}>Members</Button>{/if}
{/if} {/if}
{:else if editMode} {:else if editMode}
<Edit on:deletion on:update bind:group bind:editMode /> <Edit on:deletion on:update bind:group bind:editMode />

View File

@ -21,6 +21,7 @@
let member: Member; let member: Member;
let groups: Group[] = []; let groups: Group[] = [];
let systemGroups: Group[] = []; let systemGroups: Group[] = [];
let systemMembers: Member[] = [];
let isMainDash = false; let isMainDash = false;
let isDeleted = false; let isDeleted = false;
@ -60,13 +61,19 @@
async function fetchGroups() { async function fetchGroups() {
try { try {
groups = await api().members($params.id).groups().get({auth: !isPublic}); groups = await api().members($params.id).groups().get({auth: !isPublic, query: { with_members: !isPublic } });
if (!isPublic) { if (!isPublic) {
await new Promise(resolve => setTimeout(resolve, 1000)); await new Promise(resolve => setTimeout(resolve, 1000));
systemGroups = await api().systems("@me").groups.get({ auth: true, query: { with_members: true } }); systemGroups = await api().systems("@me").groups.get({ auth: true, query: { with_members: true } });
} }
groupErr = ""; groupErr = "";
groupLoading = false; groupLoading = false;
// we can't use with_members from a group list from a member endpoint yet, but I'm leaving this in in case we do
// (this is needed for editing a group member list from the member page)
/* if (!isPublic) {
await new Promise(resolve => setTimeout(resolve, 1000));
systemMembers = await api().systems("@me").members.get({auth: true});
} */
} catch (error) { } catch (error) {
console.log(error); console.log(error);
groupErr = error.message; groupErr = error.message;
@ -84,6 +91,15 @@
isDeleted = true; isDeleted = true;
} }
function updateGroupList(event: any) {
groups = groups.map(group => group.id !== event.detail.id ? group : event.detail);
systemGroups = systemGroups.map(group => group.id !== event.detail.id ? group : event.detail);
}
function deleteGroupFromList(event: any) {
groups = groups.filter(group => group.id !== event.detail);
systemGroups = systemGroups.filter(group => group.id !== event.detail);
}
</script> </script>
{#if settings && settings.appearance.color_background} {#if settings && settings.appearance.color_background}
@ -139,14 +155,14 @@
<CardsHeader bind:item={group} slot="header"> <CardsHeader bind:item={group} slot="header">
<FaUsers slot="icon" /> <FaUsers slot="icon" />
</CardsHeader> </CardsHeader>
<GroupBody isMainDash={isMainDash} bind:group bind:isPublic={isPublic}/> <GroupBody bind:members={systemMembers} on:update={updateGroupList} isMainDash={isMainDash} on:deletion={deleteGroupFromList} bind:group bind:isPublic={isPublic}/>
</AccordionItem> </AccordionItem>
{:else} {:else}
<AccordionItem> <AccordionItem>
<CardsHeader bind:item={group} slot="header"> <CardsHeader bind:item={group} slot="header">
<FaLock slot="icon" /> <FaLock slot="icon" />
</CardsHeader> </CardsHeader>
<GroupBody isMainDash={isMainDash} bind:group bind:isPublic={isPublic}/> <GroupBody bind:members={systemMembers} on:update={updateGroupList} isMainDash={isMainDash} on:deletion={deleteGroupFromList} bind:group bind:isPublic={isPublic}/>
</AccordionItem> </AccordionItem>
{/if} {/if}
{/each} {/each}