feat: add toasts when editing profile/members

This commit is contained in:
Sam 2023-03-15 00:01:13 +01:00
parent 87e6e2809e
commit 7477814c1b
No known key found for this signature in database
GPG Key ID: B4EF20DDE721CAA1
2 changed files with 22 additions and 0 deletions

View File

@ -31,6 +31,7 @@
import EditablePronouns from "../../EditablePronouns.svelte";
import ErrorAlert from "$lib/components/ErrorAlert.svelte";
import type { PageData } from "./$types";
import { addToast, delToast } from "$lib/toast";
const MAX_AVATAR_BYTES = 1_000_000;
@ -213,6 +214,12 @@
};
const updateMember = async () => {
const toastId = addToast({
header: "Saving changes",
body: "Saving changes, please wait...",
duration: -1,
});
try {
const resp = await apiFetchClient<Member>(`/members/${data.member.id}`, "PATCH", {
name,
@ -225,12 +232,16 @@
fields,
});
addToast({ header: "Success", body: "Successfully saved changes!" });
data.member = resp;
avatar = null;
error = null;
modified = false;
} catch (e) {
error = e as APIError;
} finally {
delToast(toastId);
}
};

View File

@ -28,6 +28,7 @@
import EditableName from "../EditableName.svelte";
import EditablePronouns from "../EditablePronouns.svelte";
import ErrorAlert from "$lib/components/ErrorAlert.svelte";
import { addToast, delToast } from "$lib/toast";
const MAX_AVATAR_BYTES = 1_000_000;
@ -216,6 +217,12 @@
};
const updateUser = async () => {
const toastId = addToast({
header: "Saving changes",
body: "Saving changes, please wait...",
duration: -1,
});
try {
const resp = await apiFetchClient<MeUser>("/users/@me", "PATCH", {
display_name,
@ -230,11 +237,15 @@
userStore.set(resp);
localStorage.setItem("pronouns-user", JSON.stringify(resp));
addToast({ header: "Success", body: "Successfully saved changes!" });
avatar = null;
error = null;
modified = false;
} catch (e) {
error = e as APIError;
} finally {
delToast(toastId);
}
};
</script>