fix: fix some... issues with bulk privacy

This commit is contained in:
Draconizations 2022-05-14 23:51:39 +02:00
parent edf19d3f6f
commit 778307add7
2 changed files with 29 additions and 25 deletions

View File

@ -13,16 +13,16 @@
let success = false; let success = false;
// kinda hacked together from typescript's Required<T> type // kinda hacked together from typescript's Required<T> type
const privacy: GroupPrivacy = { const privacy: { [P in keyof GroupPrivacy]-?: string; } = {
name_privacy: "public", description_privacy: "no change",
description_privacy: "public", name_privacy: "no change",
icon_privacy: "public", list_privacy: "no change",
list_privacy: "public", icon_privacy: "no change",
metadata_privacy: "public", visibility: "no change",
visibility: "public", metadata_privacy: "no change",
}; };
const privacyNames: GroupPrivacy = { const privacyNames: { [P in keyof GroupPrivacy]-?: string; } = {
name_privacy: "Name", name_privacy: "Name",
description_privacy: "Description", description_privacy: "Description",
icon_privacy: "Icon", icon_privacy: "Icon",
@ -31,12 +31,11 @@
visibility: "Visbility", visibility: "Visbility",
}; };
let setPrivate = true;
async function submit() { async function submit() {
success = false; success = false;
loading = true; loading = true;
const data = privacy; const dataArray = Object.entries(privacy).filter(([, value]) => value === "no change" ? false : true);
const data = Object.fromEntries(dataArray);
try { try {
await api().private.bulk_privacy.group.post({ data }); await api().private.bulk_privacy.group.post({ data });
success = true; success = true;
@ -69,10 +68,11 @@
<Alert color="danger">{err}</Alert> <Alert color="danger">{err}</Alert>
{/if} {/if}
{#if success} {#if success}
<Alert color="success">Member privacy updated!</Alert> <Alert color="success">Group privacy updated!</Alert>
{/if} {/if}
<Label><b>Set all to:</b></Label> <Label><b>Set all to:</b></Label>
<Input type="select" on:change={(e) => changeAll(e)}> <Input type="select" on:change={(e) => changeAll(e)}>
<option>no change</option>
<option>public</option> <option>public</option>
<option>private</option> <option>private</option>
</Input> </Input>
@ -82,8 +82,9 @@
<Col xs={12} lg={6} class="mb-3"> <Col xs={12} lg={6} class="mb-3">
<Label>{privacyNames[x]}:</Label> <Label>{privacyNames[x]}:</Label>
<Input type="select" bind:value={privacy[x]}> <Input type="select" bind:value={privacy[x]}>
<option default={privacy[x] === "public"}>public</option> <option default>no change</option>
<option default={privacy[x] === "private"}>private</option> <option>public</option>
<option>private</option>
</Input> </Input>
</Col> </Col>
{/each} {/each}

View File

@ -13,17 +13,17 @@ import Member from './Member.svelte';
let err = ""; let err = "";
let success = false; let success = false;
const privacy: MemberPrivacy = { const privacy: { [P in keyof MemberPrivacy]-?: string; } = {
description_privacy: "public", description_privacy: "no change",
name_privacy: "public", name_privacy: "no change",
avatar_privacy: "public", avatar_privacy: "no change",
birthday_privacy: "public", birthday_privacy: "no change",
pronoun_privacy: "public", pronoun_privacy: "no change",
visibility: "public", visibility: "no change",
metadata_privacy: "public", metadata_privacy: "no change",
}; };
const privacyNames: MemberPrivacy = { const privacyNames: { [P in keyof MemberPrivacy]-?: string; } = {
avatar_privacy: "Avatar", avatar_privacy: "Avatar",
birthday_privacy: "Birthday", birthday_privacy: "Birthday",
description_privacy: "Description", description_privacy: "Description",
@ -36,7 +36,8 @@ import Member from './Member.svelte';
async function submit() { async function submit() {
success = false; success = false;
loading = true; loading = true;
const data = privacy; const dataArray = Object.entries(privacy).filter(([, value]) => value === "no change" ? false : true);
const data = Object.fromEntries(dataArray);
try { try {
await api().private.bulk_privacy.member.post({ data }); await api().private.bulk_privacy.member.post({ data });
success = true; success = true;
@ -73,6 +74,7 @@ import Member from './Member.svelte';
{/if} {/if}
<Label><b>Set all to:</b></Label> <Label><b>Set all to:</b></Label>
<Input type="select" on:change={(e) => changeAll(e)}> <Input type="select" on:change={(e) => changeAll(e)}>
<option>no change</option>
<option>public</option> <option>public</option>
<option>private</option> <option>private</option>
</Input> </Input>
@ -82,7 +84,8 @@ import Member from './Member.svelte';
<Col xs={12} lg={6} class="mb-3"> <Col xs={12} lg={6} class="mb-3">
<Label>{privacyNames[x]}:</Label> <Label>{privacyNames[x]}:</Label>
<Input type="select" bind:value={privacy[x]}> <Input type="select" bind:value={privacy[x]}>
<option default>public</option> <option default>no change</option>
<option>public</option>
<option>private</option> <option>private</option>
</Input> </Input>
</Col> </Col>