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

View File

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