flotilla/src/app/components/ProfileEdit.svelte

36 lines
1.3 KiB
Svelte
Raw Normal View History

2024-11-15 22:25:18 +00:00
<script lang="ts">
2025-02-14 18:53:36 +00:00
import type {Profile} from "@welshman/util"
import {getTag, makeProfile} from "@welshman/util"
import {pubkey, profilesByPubkey} from "@welshman/app"
2026-02-20 22:21:38 +00:00
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
import Icon from "@lib/components/Icon.svelte"
2024-11-15 22:25:18 +00:00
import Button from "@lib/components/Button.svelte"
2025-02-14 18:53:36 +00:00
import ProfileEditForm from "@app/components/ProfileEditForm.svelte"
import {clearModals} from "@app/util/modal"
import {pushToast} from "@app/util/toast"
import {PROTECTED} from "@app/core/state"
2026-01-16 18:06:25 +00:00
import {updateProfile} from "@app/core/commands"
2024-11-15 22:25:18 +00:00
2025-04-15 16:36:39 +00:00
const profile = $profilesByPubkey.get($pubkey!) || makeProfile()
const shouldBroadcast = !getTag(PROTECTED, profile.event?.tags || [])
const initialValues = {profile, shouldBroadcast}
2024-11-15 22:25:18 +00:00
const back = () => history.back()
2025-04-15 16:36:39 +00:00
const onsubmit = ({profile, shouldBroadcast}: {profile: Profile; shouldBroadcast: boolean}) => {
updateProfile({profile, shouldBroadcast})
2024-11-15 22:25:18 +00:00
pushToast({message: "Your profile has been updated!"})
clearModals()
}
</script>
2025-02-14 18:53:36 +00:00
<ProfileEditForm {initialValues} {onsubmit}>
{#snippet footer()}
2026-02-20 22:21:38 +00:00
<Button class="btn btn-link" onclick={back}>
<Icon icon={AltArrowLeft} />
Go Back
</Button>
<Button type="submit" class="btn btn-primary">Save Changes</Button>
2025-02-14 18:53:36 +00:00
{/snippet}
</ProfileEditForm>