flotilla/src/app/components/ProfileEdit.svelte

84 lines
2.6 KiB
Svelte
Raw Normal View History

2024-11-15 22:25:18 +00:00
<script lang="ts">
2025-02-04 00:37:14 +00:00
import {preventDefault} from "svelte/legacy"
2024-11-15 22:25:18 +00:00
import {ctx} from "@welshman/lib"
import {
createEvent,
makeProfile,
editProfile,
createProfile,
isPublishedProfile,
} from "@welshman/util"
import {pubkey, profilesByPubkey, publishThunk} from "@welshman/app"
import Icon from "@lib/components/Icon.svelte"
import Field from "@lib/components/Field.svelte"
import Button from "@lib/components/Button.svelte"
import InputProfilePicture from "@lib/components/InputProfilePicture.svelte"
import InfoHandle from "@app/components/InfoHandle.svelte"
import {pushModal, clearModals} from "@app/modal"
import {pushToast} from "@app/toast"
2025-02-04 00:37:14 +00:00
const values = $state({...($profilesByPubkey.get($pubkey!) || makeProfile())})
2024-11-15 22:25:18 +00:00
const back = () => history.back()
const saveEdit = () => {
const relays = ctx.app.router.FromUser().getUrls()
const template = isPublishedProfile(values) ? editProfile(values) : createProfile(values)
const event = createEvent(template.kind, template)
publishThunk({event, relays})
pushToast({message: "Your profile has been updated!"})
clearModals()
}
2025-02-04 00:37:14 +00:00
let file: File | undefined = $state()
2024-11-15 22:25:18 +00:00
</script>
2025-02-04 00:37:14 +00:00
<form class="col-4" onsubmit={preventDefault(saveEdit)}>
2024-11-15 22:25:18 +00:00
<div class="flex justify-center py-2">
<InputProfilePicture bind:file bind:url={values.picture} />
</div>
<Field>
2025-02-04 00:37:14 +00:00
{#snippet label()}
<p>Username</p>
{/snippet}
{#snippet input()}
<label class="input input-bordered flex w-full items-center gap-2">
<Icon icon="user-circle" />
<input bind:value={values.name} class="grow" type="text" />
</label>
{/snippet}
2024-11-15 22:25:18 +00:00
</Field>
<Field>
2025-02-04 00:37:14 +00:00
{#snippet label()}
<p>About You</p>
{/snippet}
{#snippet input()}
<textarea class="textarea textarea-bordered leading-4" rows="3" bind:value={values.about}>
</textarea>
{/snippet}
2024-11-15 22:25:18 +00:00
</Field>
<Field>
2025-02-04 00:37:14 +00:00
{#snippet label()}
<p>Nostr Address</p>
{/snippet}
{#snippet input()}
<label class="input input-bordered flex w-full items-center gap-2">
<Icon icon="map-point" />
<input bind:value={values.nip05} class="grow" type="text" />
</label>
{/snippet}
{#snippet info()}
<p>
<Button class="link" on:click={() => pushModal(InfoHandle)}
>What is a nostr address?</Button>
</p>
{/snippet}
2024-11-15 22:25:18 +00:00
</Field>
<div class="mt-4 flex flex-row items-center justify-between gap-4">
<Button class="btn btn-neutral" on:click={back}>Discard Changes</Button>
<Button type="submit" class="btn btn-primary">Save Changes</Button>
</div>
</form>