feat: system privacy editing

This commit is contained in:
Spectralitree 2021-12-12 08:59:34 +01:00
parent 9f1679f161
commit f6bf75e80a
2 changed files with 86 additions and 3 deletions

View File

@ -1,10 +1,13 @@
<script lang="ts">
import { Card, CardHeader, CardBody, CardTitle, Row, Col, Button } from 'sveltestrap';
import { Card, CardHeader, CardBody, CardTitle, Row, Col, Button, Spinner } from 'sveltestrap';
import FaUserLock from 'svelte-icons/fa/FaUserLock.svelte';
import type Sys from '../../api/system';
import PrivacyEdit from './PrivacyEdit.svelte';
export let user: Sys;
let editMode = false;
let loading: boolean;
</script>
<Card class="mb-4">
@ -13,11 +16,12 @@
<div class="icon d-inline-block">
<FaUserLock />
</div> System privacy
{#if loading}<div class="d-inline-block mr-5" style="float: right;"><Spinner color="primary" /></div>{/if}
</CardTitle>
</CardHeader>
<CardBody>
<CardBody style="border-left: 4px solid #{user.color}">
{#if editMode}
stuff
<PrivacyEdit bind:loading bind:user={user} bind:editMode/>
{:else}
<Row>
<Col xs={12} lg={4} class="mb-3">

View File

@ -0,0 +1,79 @@
<script lang="ts">
import Sys from '../../api/system';
import { Input, Row, Col, Button, Label } from 'sveltestrap';
import { currentUser } from '../../stores';
import PKAPI from '../../api';
export let loading = false;
export let user: Sys;
export let editMode: boolean;
let err: string;
let input = new Sys(user);
async function submit() {
let data = input;
err = null;
loading = true;
const api = new PKAPI();
try {
let res = await api.patchSystem({token: localStorage.getItem("pk-token"), data: data});
user = res;
currentUser.update(() => res);
editMode = false;
loading = false;
} catch (error) {
console.log(error);
err = error.message;
err = err;
loading = false;
}
}
</script>
<Label><b>Set all to:</b></Label>
<Input type="select" bind:value={input.privacy.description_privacy}>
<option default>public</option>
<option>private</option>
</Input>
<hr />
<Row>
<Col xs={12} lg={4} class="mb-3">
<Label>Description:</Label>
<Input type="select" bind:value={input.privacy.description_privacy}>
<option default={user.privacy.description_privacy === "public"}>public</option>
<option default={user.privacy.description_privacy === "private"}>private</option>
</Input>
</Col>
<Col xs={12} lg={4} class="mb-3">
<Label>Member list:</Label>
<Input type="select" bind:value={input.privacy.member_list_privacy}>
<option default={user.privacy.member_list_privacy === "public"}>public</option>
<option default={user.privacy.member_list_privacy === "private"}>private</option>
</Input>
</Col>
<Col xs={12} lg={4} class="mb-3">
<Label>Group list:</Label>
<Input type="select" bind:value={input.privacy.group_list_privacy}>
<option default={user.privacy.group_list_privacy === "public"}>public</option>
<option default={user.privacy.group_list_privacy === "private"}>private</option>
</Input>
</Col>
<Col xs={12} lg={4} class="mb-3">
<Label>Current front:</Label>
<Input type="select" bind:value={input.privacy.front_privacy}>
<option default={user.privacy.front_privacy === "public"}>public</option>
<option default={user.privacy.front_privacy === "private"}>private</option>
</Input>
</Col>
<Col xs={12} lg={4} class="mb-3">
<Label>Front history:</Label>
<Input type="select" bind:value={input.privacy.front_history_privacy}>
<option default={user.privacy.front_history_privacy === "public"}>public</option>
<option default={user.privacy.front_history_privacy === "private"}>private</option>
</Input>
</Col>
</Row>
<Button style="flex: 0" color="primary" on:click={submit}>Submit</Button> <Button style="flex: 0" color="light" on:click={() => editMode = false}>Back</Button>