flotilla/src/app/components/ProfileEdit.svelte

39 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"
2024-11-15 22:25:18 +00:00
import {
createEvent,
makeProfile,
editProfile,
createProfile,
isPublishedProfile,
} from "@welshman/util"
2025-04-09 22:32:18 +00:00
import {Router, pubkey, profilesByPubkey, publishThunk} from "@welshman/app"
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/modal"
2024-11-15 22:25:18 +00:00
import {pushToast} from "@app/toast"
2025-02-14 18:53:36 +00:00
const initialValues = {...($profilesByPubkey.get($pubkey!) || makeProfile())}
2024-11-15 22:25:18 +00:00
const back = () => history.back()
2025-02-14 18:53:36 +00:00
const onsubmit = (profile: Profile) => {
2025-04-09 22:32:18 +00:00
const relays = Router.get().FromUser().getUrls()
2025-02-14 18:53:36 +00:00
const template = isPublishedProfile(profile) ? editProfile(profile) : createProfile(profile)
2024-11-15 22:25:18 +00:00
const event = createEvent(template.kind, template)
publishThunk({event, relays})
pushToast({message: "Your profile has been updated!"})
clearModals()
}
</script>
2025-02-14 18:53:36 +00:00
<ProfileEditForm {initialValues} {onsubmit}>
{#snippet footer()}
<div class="mt-4 flex flex-row items-center justify-between gap-4">
<Button class="btn btn-neutral" onclick={back}>Discard Changes</Button>
<Button type="submit" class="btn btn-primary">Save Changes</Button>
</div>
{/snippet}
</ProfileEditForm>