mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-12 00:30:11 +00:00
refactor(dashboard): use svelte context for lists
This commit is contained in:
parent
f2e160c526
commit
a48f2b40c4
23 changed files with 598 additions and 433 deletions
|
|
@ -1,14 +1,17 @@
|
|||
<script lang="ts">
|
||||
import { tick, createEventDispatcher } from "svelte";
|
||||
import { tick, getContext } from "svelte";
|
||||
import { ModalBody, ModalHeader, Col, Row, Input, Label, ModalFooter, Button, Spinner, Alert } from "sveltestrap";
|
||||
|
||||
import type { Group, GroupPrivacy } from '../../api/types';
|
||||
import api from '../../api';
|
||||
import type { Writable } from "svelte/store";
|
||||
|
||||
export let privacyOpen: boolean;
|
||||
export let group: Group;
|
||||
const togglePrivacyModal = () => (privacyOpen = !privacyOpen);
|
||||
|
||||
$: groups = getContext<Writable<Group[]>>("groups")
|
||||
|
||||
let err: string;
|
||||
let loading = false;
|
||||
let success = false;
|
||||
|
|
@ -18,12 +21,6 @@
|
|||
Object.keys(privacy).forEach(x => privacy[x] = target.value);
|
||||
}
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
function update(group) {
|
||||
dispatch('update', group);
|
||||
}
|
||||
|
||||
// I can't use the hacked together Required<T> type from the bulk privacy here
|
||||
// that breaks updating the displayed privacy after submitting
|
||||
// but there's not really any way for any privacy fields here to be missing
|
||||
|
|
@ -43,7 +40,15 @@
|
|||
const data: Group = {privacy: privacy};
|
||||
try {
|
||||
let res = await api().groups(group.id).patch({data});
|
||||
group = {...group, ...res};
|
||||
const newgroup = {...group, ...res};
|
||||
const newList = $groups.map((g: Group) => {
|
||||
if (group.uuid === g.uuid) {
|
||||
g = newgroup
|
||||
}
|
||||
return g
|
||||
})
|
||||
groups.set(newList);
|
||||
|
||||
success = true;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue