flotilla/src/app/components/ProfileEdit.svelte

53 lines
1.6 KiB
Svelte
Raw Normal View History

2024-11-15 22:25:18 +00:00
<script lang="ts">
2026-02-20 22:21:38 +00:00
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
2026-03-06 22:18:05 +00:00
import {errorMessage} from "@lib/util"
2026-02-20 22:21:38 +00:00
import Icon from "@lib/components/Icon.svelte"
2024-11-15 22:25:18 +00:00
import Button from "@lib/components/Button.svelte"
2026-03-06 22:18:05 +00:00
import Spinner from "@lib/components/Spinner.svelte"
2025-02-14 18:53:36 +00:00
import ProfileEditForm from "@app/components/ProfileEditForm.svelte"
2026-07-28 16:16:26 +00:00
import type {Values} from "@app/components/ProfileEditForm.svelte"
2026-06-08 21:14:40 +00:00
import {clearModals} from "@app/modal"
import {pushToast} from "@app/toast"
2026-07-28 16:16:26 +00:00
import {profiles, user} from "@app/core"
2024-11-15 22:25:18 +00:00
2026-07-28 16:16:26 +00:00
const initialValues = {profile: {...$profiles.get($user.pubkey)?.values}}
2024-11-15 22:25:18 +00:00
const back = () => history.back()
2026-07-28 16:16:26 +00:00
const onsubmit = async ({profile}: Values) => {
2026-03-06 22:18:05 +00:00
loading = true
try {
2026-07-28 16:16:26 +00:00
const command = await $profiles.update(writer => writer.update(profile))
const error = await command.publish().waitForError()
2026-03-06 22:18:05 +00:00
if (error) {
pushToast({
theme: "error",
message: `Failed to update your profile: ${errorMessage(error)}`,
})
} else {
pushToast({message: "Your profile has been updated!"})
clearModals()
}
} finally {
loading = false
}
2024-11-15 22:25:18 +00:00
}
2026-03-06 22:18:05 +00:00
let loading = $state(false)
2024-11-15 22:25:18 +00:00
</script>
2025-02-14 18:53:36 +00:00
<ProfileEditForm {initialValues} {onsubmit}>
{#snippet footer()}
<Button class="button button-link" onclick={back}>
2026-02-20 22:21:38 +00:00
<Icon icon={AltArrowLeft} />
Go Back
</Button>
<Button type="submit" class="button button-primary" disabled={loading}>
2026-03-06 22:18:05 +00:00
<Spinner {loading} />
Save Changes
</Button>
2025-02-14 18:53:36 +00:00
{/snippet}
</ProfileEditForm>