flotilla/src/app/components/ProfileEditForm.svelte

112 lines
3.4 KiB
Svelte
Raw Normal View History

2025-02-14 18:53:36 +00:00
<script lang="ts">
import type {Snippet} from "svelte"
import type {Profile} from "@welshman/util"
import {preventDefault} from "@lib/html"
2025-09-10 22:26:39 +00:00
import UserCircle from "@assets/icons/user-circle.svg?dataurl"
import MapPoint from "@assets/icons/map-point.svg?dataurl"
2025-02-14 18:53:36 +00:00
import Icon from "@lib/components/Icon.svelte"
import Field from "@lib/components/Field.svelte"
import Button from "@lib/components/Button.svelte"
2026-01-30 22:14:12 +00:00
import Modal from "@lib/components/Modal.svelte"
import ModalBody from "@lib/components/ModalBody.svelte"
2026-02-20 22:21:38 +00:00
import ModalFooter from "@lib/components/ModalFooter.svelte"
import InputProfilePicture from "@app/components/InputProfilePicture.svelte"
2025-02-14 18:53:36 +00:00
import InfoHandle from "@app/components/InfoHandle.svelte"
2026-06-08 21:14:40 +00:00
import {pushModal} from "@app/modal"
2025-02-14 18:53:36 +00:00
2025-04-15 16:36:39 +00:00
type Values = {
profile: Profile
}
2025-02-14 18:53:36 +00:00
type Props = {
2025-04-15 16:36:39 +00:00
initialValues: Values
onsubmit: (values: Values) => void
2025-08-18 22:02:17 +00:00
isSignup?: boolean
2025-02-14 18:53:36 +00:00
footer: Snippet
progressBar?: Snippet
2025-02-14 18:53:36 +00:00
}
const {initialValues, isSignup, onsubmit, footer, progressBar}: Props = $props()
2025-02-14 18:53:36 +00:00
const values = $state(initialValues)
const submit = () => onsubmit($state.snapshot(values))
let file: File | undefined = $state()
</script>
2026-01-30 22:14:12 +00:00
<Modal tag="form" onsubmit={preventDefault(submit)}>
<ModalBody>
{#if isSignup}
<div class="grid grid-cols-2">
<div class="flex flex-col gap-2">
<p class="text-2xl">Create a Profile</p>
<p class="text-sm">
Give people something to go on — but remember, privacy matters! Be careful about sharing
sensitive information.
</p>
</div>
<div class="flex flex-col items-center justify-center gap-2">
<InputProfilePicture bind:file bind:url={values.profile.picture} />
<p class="text-xs">Upload an Avatar</p>
</div>
2025-08-18 22:02:17 +00:00
</div>
2026-01-30 22:14:12 +00:00
{:else}
<div class="flex items-center justify-center py-4">
2025-08-18 22:02:17 +00:00
<InputProfilePicture bind:file bind:url={values.profile.picture} />
</div>
2026-01-30 22:14:12 +00:00
{/if}
2025-02-14 18:53:36 +00:00
<Field>
{#snippet label()}
2026-01-30 22:14:12 +00:00
<p>Nickname</p>
2025-02-14 18:53:36 +00:00
{/snippet}
{#snippet input()}
<label class="input flex w-full items-center gap-2">
2026-01-30 22:14:12 +00:00
<Icon icon={UserCircle} />
<input bind:value={values.profile.name} class="grow" type="text" />
2025-02-14 18:53:36 +00:00
</label>
{/snippet}
{#snippet info()}
2026-01-30 22:14:12 +00:00
What would you like people to call you?
2025-02-14 18:53:36 +00:00
{/snippet}
</Field>
2026-01-30 22:14:12 +00:00
<Field>
2025-08-18 22:02:17 +00:00
{#snippet label()}
2026-01-30 22:14:12 +00:00
<p>About You</p>
2025-08-18 22:02:17 +00:00
{/snippet}
{#snippet input()}
<textarea class="textarea input leading-4 w-full" rows="5" bind:value={values.profile.about}
></textarea>
2025-08-18 22:02:17 +00:00
{/snippet}
{#snippet info()}
2026-01-30 22:14:12 +00:00
Give a brief introduction to why you're here.
2025-08-18 22:02:17 +00:00
{/snippet}
2026-01-30 22:14:12 +00:00
</Field>
{#if !isSignup}
<Field>
{#snippet label()}
<p>Nostr Address</p>
{/snippet}
{#snippet input()}
<label class="input flex w-full items-center gap-2">
2026-01-30 22:14:12 +00:00
<Icon icon={MapPoint} />
<input bind:value={values.profile.nip05} class="grow" type="text" />
</label>
{/snippet}
{#snippet info()}
<p>
<Button class="button button-link" onclick={() => pushModal(InfoHandle)}
2026-01-30 22:14:12 +00:00
>What is a nostr address?</Button>
</p>
{/snippet}
</Field>
{/if}
</ModalBody>
{#if progressBar}
{@render progressBar()}
{/if}
2026-02-20 22:21:38 +00:00
<ModalFooter>
{@render footer()}
</ModalFooter>
2026-01-30 22:14:12 +00:00
</Modal>