flotilla/src/app/components/SignUp.svelte

118 lines
4 KiB
Svelte
Raw Normal View History

2024-08-16 22:17:30 +00:00
<script lang="ts">
2026-01-16 18:06:25 +00:00
import type {ClientOptions} from "@pomade/core"
import type {Profile} from "@welshman/util"
import {makeProfile, makeSecret, RELAYS, MESSAGING_RELAYS, makeEvent} from "@welshman/util"
import {loginWithNip01, publishThunk} from "@welshman/app"
2025-09-10 22:26:39 +00:00
import Key from "@assets/icons/key-minimalistic.svg?dataurl"
2025-12-18 02:43:13 +00:00
import Letter from "@assets/icons/letter.svg?dataurl"
2026-01-16 18:06:25 +00:00
import {getKey, setKey} from "@lib/implicit"
2024-08-16 22:17:30 +00:00
import Icon from "@lib/components/Icon.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"
2024-08-16 22:17:30 +00:00
import LogIn from "@app/components/LogIn.svelte"
2026-01-16 18:06:25 +00:00
import SignUpKey from "@app/components/SignUpKey.svelte"
import SignUpEmail from "@app/components/SignUpEmail.svelte"
2025-08-18 22:02:17 +00:00
import SignUpProfile from "@app/components/SignUpProfile.svelte"
2026-01-16 18:06:25 +00:00
import SignUpComplete from "@app/components/SignUpComplete.svelte"
import {initProfile} from "@app/profiles"
import {
POMADE_SIGNERS,
PLATFORM_NAME,
INDEXER_RELAYS,
DEFAULT_RELAYS,
DEFAULT_MESSAGING_RELAYS,
2026-06-10 00:19:44 +00:00
DEFAULT_SPACES,
} from "@app/env"
2026-06-08 21:14:40 +00:00
import {setChecked} from "@app/notifications"
2026-06-10 00:19:44 +00:00
import {setSpaces} from "@app/groups"
2026-06-08 21:14:40 +00:00
import {loginWithPomade} from "@app/pomade"
import {pushModal, clearModals} from "@app/modal"
2024-12-03 00:21:54 +00:00
2026-01-16 18:06:25 +00:00
setKey("signup.email", "")
setKey("signup.secret", makeSecret())
setKey("signup.profile", makeProfile())
setKey("signup.clientOptions", undefined)
2025-12-18 02:43:13 +00:00
const hasPomade = POMADE_SIGNERS.length >= 3
2024-12-03 00:21:54 +00:00
2025-12-18 02:43:13 +00:00
const login = () => pushModal(LogIn)
2024-08-16 22:17:30 +00:00
const completeSignup = () => {
// Add default outbox/inbox relays
publishThunk({
event: makeEvent(RELAYS, {tags: DEFAULT_RELAYS.map(url => ["r", url])}),
relays: [...INDEXER_RELAYS, ...DEFAULT_RELAYS],
})
// Add default messaging relays
publishThunk({
event: makeEvent(MESSAGING_RELAYS, {tags: DEFAULT_MESSAGING_RELAYS.map(url => ["r", url])}),
relays: DEFAULT_RELAYS,
})
// Save the user's profile
initProfile(getKey<Profile>("signup.profile")!)
2026-06-10 00:19:44 +00:00
// Auto-join default spaces
setSpaces(DEFAULT_SPACES)
// Don't show any notifications for old content
setChecked("*")
// Go to the dashboard
clearModals()
}
2026-01-16 18:06:25 +00:00
const flows = {
email: {
start: () => pushModal(SignUpEmail, {next: flows.email.profile, step: 1, totalSteps: 3}),
profile: () => pushModal(SignUpProfile, {next: flows.email.complete, step: 2, totalSteps: 3}),
complete: () =>
pushModal(SignUpComplete, {next: flows.email.finalize, step: 3, totalSteps: 3}),
2026-01-16 18:06:25 +00:00
finalize: () => {
const email = getKey<string>("signup.email")!
const clientOptions = getKey<ClientOptions>("signup.clientOptions")!
loginWithPomade(clientOptions, email)
completeSignup()
2026-01-16 18:06:25 +00:00
},
},
nostr: {
start: () => pushModal(SignUpProfile, {next: flows.nostr.key, step: 1, totalSteps: 3}),
key: () => pushModal(SignUpKey, {next: flows.nostr.complete, step: 2, totalSteps: 3}),
complete: () =>
pushModal(SignUpComplete, {next: flows.nostr.finalize, step: 3, totalSteps: 3}),
2026-01-16 18:06:25 +00:00
finalize: () => {
const secret = getKey<string>("signup.secret")!
2025-02-14 18:53:36 +00:00
2026-01-16 18:06:25 +00:00
loginWithNip01(secret)
completeSignup()
2026-01-16 18:06:25 +00:00
},
},
}
2024-08-16 22:17:30 +00:00
</script>
2026-01-30 22:14:12 +00:00
<Modal>
<ModalBody>
<h1 class="heading">Join {PLATFORM_NAME}</h1>
2026-01-30 22:14:12 +00:00
<p class="m-auto max-w-sm text-center">
2026-05-25 16:04:14 +00:00
Censorship resistant digital spaces for communities. Meet new people, own your identity.
2026-01-30 22:14:12 +00:00
</p>
{#if hasPomade}
<Button onclick={flows.email.start} class="btn btn-primary">
<Icon icon={Letter} />
Sign up with email
</Button>
{/if}
<Button onclick={flows.nostr.start} class="btn {hasPomade ? 'btn-neutral' : 'btn-primary'}">
<Icon icon={Key} />
Generate a key
2024-11-27 00:39:49 +00:00
</Button>
2026-01-30 22:14:12 +00:00
<div class="text-sm">
Already have an account?
<Button class="link" onclick={login}>Log in instead</Button>
</div>
</ModalBody>
</Modal>