impr: make signup page more user friendly

This commit is contained in:
James Xylight committed 2025-07-11 12:31:17 -07:00
1 parent 020b0080a5
commit 8dd734fc24
8 files changed
+350 -181

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
<script lang="ts">
import { t } from '$lib/i18n/translations'
import { Button } from 'mono-svelte'
import { ArrowLeft, Icon } from 'svelte-hero-icons'
let { children } = $props()
</script>
<div
class="fixed inset-0 bg-slate-50 dark:bg-zinc-925 z-50 p-8 sm:p-16 lg:p-24 overflow-auto"
>
{@render children?.()}
</div>
+42 -38
View File
@@ -17,13 +17,15 @@
import { preventDefault } from 'svelte/legacy'
import { goto } from '$app/navigation'
import VirtualList from '$lib/components/render/VirtualList.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import { t } from '$lib/i18n/translations'
import { DEFAULT_INSTANCE_URL } from '$lib/instance.svelte.js'
import { validateInstance } from '$lib/lemmy.svelte.js'
import { Button, Material, Spinner, TextInput, toast } from 'mono-svelte'
import { Button, TextInput, toast } from 'mono-svelte'
import { onMount } from 'svelte'
import { ArrowLeft, Icon } from 'svelte-hero-icons'
let selectedInstance: string = $state('')
let validating: boolean = $state(false)
@@ -65,49 +67,51 @@
</svelte:head>
<div class="mx-auto max-w-xl flex flex-col gap-4 my-auto h-max w-full">
<Button href="/accounts" class="inline-block mb-4 w-max" rounding="pill">
<Icon src={ArrowLeft} size="16" micro />
{$t('common.back')}
</Button>
<Header>{$t('form.signup.title')}</Header>
<p>{$t('form.signup.description')}</p>
<p>
{$t('form.signup.info')}
</p>
<Material color="distinct" class="h-96 overflow-auto" rounding="2xl">
<div
class="flex flex-col h-full divide-y divide-slate-200 dark:divide-zinc-800"
{#if instances}
<VirtualList
items={instances}
useWindow={false}
height={400}
estimatedHeight={50}
class="overflow-auto border rounded-2xl border-slate-200 dark:border-zinc-900 bg-white dark:bg-zinc-950
divide-y divide-slate-200 dark:divide-zinc-900"
>
{#if instances}
{#each instances as instance (instance)}
<button
onclick={() => (selectedInstance = instance.baseurl ?? '')}
class="flex flex-row gap-2 text-left py-2 first:pt-0 last:pb-0 items-center
h-16 max-h-16 min-h-16 overflow-hidden w-full"
>
<Avatar
width={32}
url={instance.icon}
alt={instance.name}
class="shrink-0"
/>
<div class="flex flex-col max-h-full w-full">
<span
class="font-medium text-base whitespace-nowrap text-ellipsis"
>
{instance.name}
</span>
<span
class="whitespace-nowrap text-ellipsis overflow-hidden w-full"
>
{instance.desc}
</span>
</div>
</button>
{/each}
{:else}
<div class="mx-auto my-auto self-center justify-self-center">
<Spinner width={32} />
</div>
{/if}
</div>
</Material>
{#snippet item(i)}
<button
onclick={() => (selectedInstance = instances![i].baseurl ?? '')}
class="flex flex-row gap-2 text-left py-2 first:pt-0 last:pb-0 items-center
h-16 max-h-16 min-h-16 overflow-hidden w-full cursor-pointer hover:bg-slate-50 hover:dark:bg-zinc-925 duration-100
p-4"
>
<Avatar
width={32}
url={instances![i].icon}
alt={instances![i].name}
class="shrink-0"
/>
<div class="flex flex-col max-h-full w-full">
<span class="font-medium text-base whitespace-nowrap text-ellipsis">
{instances![i].name}
</span>
<span
class="whitespace-nowrap text-ellipsis overflow-hidden w-full"
>
{instances![i].desc}
</span>
</div>
</button>
{/snippet}
</VirtualList>
{/if}
<form
class="flex flex-col gap-4"
onsubmit={preventDefault(async () => {
+236 -126
View File
@@ -13,6 +13,7 @@
import type { GetCaptchaResponse } from 'lemmy-js-client'
import { Button, TextInput } from 'mono-svelte'
import {
ArrowLeft,
ArrowPath,
ExclamationCircle,
ExclamationTriangle,
@@ -23,13 +24,20 @@
} from 'svelte-hero-icons'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import { t } from '$lib/i18n/translations.js'
import SiteCard from '$lib/components/lemmy/SiteCard.svelte'
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
import ErrorContainer, {
clearErrorScope,
pushError,
} from '$lib/components/error/ErrorContainer.svelte'
import { errorMessage } from '$lib/lemmy/error.js'
let { data } = $props()
let stage = $state<'signup' | 'verify' | 'application'>('signup')
const instance = page.params.instance
let captchaRequired = data.site_view.local_site.captcha_enabled
let email: string | undefined = $state('')
$effect(() => {
@@ -44,7 +52,8 @@
application: string = $state(''),
submitting: boolean = $state(false),
honeypot: string | undefined = $state(undefined),
nsfw: boolean = $state(false)
nsfw: boolean = $state(false),
verifying: boolean = $state(false)
const getCaptcha = async () =>
(captcha = await getClient(instance, fetch).getCaptcha())
@@ -54,6 +63,7 @@
)
async function submit() {
clearErrorScope(page.url.pathname)
submitting = true
try {
@@ -69,30 +79,25 @@
honeypot,
})
const registrationMode = data.site_view.local_site.registration_mode
if (res?.jwt) {
await setUser(res.jwt, page.params.instance, username)
await setUser(res.jwt, page.params.instance)
toast({ content: $t('toast.logIn'), type: 'success' })
goto('/')
} else if (
res.verify_email_sent ||
data.site_view.local_site.registration_mode == 'RequireApplication'
registrationMode == 'RequireApplication'
) {
if (res.verify_email_sent) {
toast({
content: $t('toast.verifyEmail'),
type: 'info',
})
}
if (
data.site_view.local_site.registration_mode == 'RequireApplication'
) {
toast({
if (res.verify_email_sent) return (stage = 'verify')
if (registrationMode == 'RequireApplication') {
return toast({
content: $t('toast.waitApplication'),
type: 'info',
})
}
goto('/')
} else {
throw new Error($t('toast.failSignup'))
}
@@ -102,126 +107,231 @@
type: 'success',
})
} catch (err) {
toast({
content: err as string,
type: 'error',
pushError({
scope: page.url.pathname,
message: errorMessage(err as string),
})
}
submitting = false
}
async function verifiedEmail() {
verifying = true
clearErrorScope(page.url.pathname)
try {
const res = await getClient(instance, fetch).login({
username_or_email: username,
password: password,
})
if (res.jwt) {
await setUser(res.jwt, page.params.instance)
goto('/')
} else if (res.verify_email_sent) {
pushError({
scope: page.url.pathname,
message: $t('form.signup.verify.error'),
})
} else {
stage = 'application'
}
} catch (err) {
pushError({
scope: page.url.pathname,
message: errorMessage(err as string),
})
}
verifying = false
}
</script>
<svelte:head>
<title>Sign up</title>
<title>{$t('account.signup')}</title>
</svelte:head>
<form
class="flex flex-col gap-4 max-w-2xl mx-auto h-full w-full"
onsubmit={preventDefault(submit)}
>
<span class="flex gap-4 items-center font-bold text-xl text-center mx-auto">
{#if data.site_view.site.icon}
<Avatar circle={false} width={48} url={data.site_view.site.icon} />
{/if}
{data.site_view.site.name}
</span>
{#if data.site_view.local_site.registration_mode != 'Closed'}
<Header>{$t('form.signup.title')}</Header>
<TextInput
bind:value={email}
label={$t('form.email')}
required={data.site_view.local_site.require_email_verification}
type="email"
/>
<TextInput bind:value={username} label={$t('form.username')} required />
<TextInput
bind:value={password}
label={$t('form.password')}
required
type="password"
/>
<TextInput
bind:value={passwordVerify}
label={$t('form.confirmPassword')}
required
type="password"
/>
{#if data.site_view.local_site.registration_mode == 'RequireApplication'}
<Material class="dark:text-yellow-200 text-yellow-800 bg-yellow-500/20">
<Icon src={ExclamationTriangle} mini size="20" />
{$t('form.signup.application.info')}
</Material>
{#if data.site_view.local_site.application_question}
<Markdown source={data.site_view.local_site.application_question} />
{/if}
<MarkdownEditor
label={$t('form.signup.application.label')}
required
bind:value={application}
/>
{/if}
{#if captchaRequired}
<div>
<div class="block my-1 font-bold text-sm">Captcha</div>
<div class="flex flex-col gap-4">
{#await getCaptcha()}
<Spinner width={32} />
{:then}
{#if captcha?.ok}
<img
src="data:image/png;base64,{captcha.ok.png}"
alt="Captcha"
class="w-max"
/>
<audio controls src={captchaAudio}></audio>
{:else}
<Material
class="flex gap-2 dark:text-yellow-200 text-yellow-800 bg-yellow-500/20"
>
<Icon src={QuestionMarkCircle} mini size="24" />
No captcha was returned
</Material>
{/if}
{:catch err}
<Material
padding="sm"
class="flex gap-2 dark:text-yellow-200 text-yellow-800 bg-yellow-500/20"
>
<Icon src={ExclamationCircle} mini size="24" />
{err}
</Material>
{/await}
<Button onclick={() => getCaptcha()} size="square-md">
<Icon src={ArrowPath} size="16" mini />
</Button>
<TextInput required bind:value={verifyCaptcha} />
</div>
</div>
{/if}
<Checkbox bind:checked={nsfw}>{$t('form.profile.showNSFW')}</Checkbox>
<input type="dn" name="honeypot" bind:value={honeypot} class="hidden" />
<Button
submit
color="primary"
size="lg"
loading={submitting}
disabled={submitting}
class="mt-auto"
<div class="flex flex-col md:flex-row flex-1/3 gap-8 h-full max-w-5xl mx-auto">
{#if stage == 'signup'}
<form
class="flex flex-col gap-4 h-full w-full flex-2/3"
onsubmit={preventDefault(submit)}
>
{$t('form.submit')}
</Button>
{:else}
<div class="my-auto">
<Placeholder
icon={XCircle}
title={$t('form.signup.closed.title')}
description={$t('form.signup.closed.description')}
>
<Button icon={Plus} href="/signup">
{$t('form.signup.closed.anotherInstance')}
<Button href="/signup" class="inline-block mb-4 w-max" rounding="pill">
<Icon src={ArrowLeft} size="16" micro />
{$t('common.back')}
</Button>
<Header>
{$t('form.signup.title')}
{#snippet extended()}
<span class="flex gap-4 items-center text-xl text-center mx-auto">
{#if data.site_view.site.icon}
<Avatar
circle={false}
width={48}
url={data.site_view.site.icon}
/>
{/if}
{data.site_view.site.name}
</span>
{/snippet}
</Header>
{#if data.site_view.local_site.registration_mode != 'Closed'}
<div class="flex flex-col md:flex-row gap-2 *:flex-1">
<TextInput
bind:value={email}
label={$t('form.email')}
required={data.site_view.local_site.require_email_verification}
type="email"
/>
<TextInput
bind:value={username}
label={$t('form.username')}
required
/>
</div>
<div class="flex flex-col md:flex-row gap-2 *:flex-1">
<TextInput
bind:value={password}
label={$t('form.password')}
required
type="password"
/>
<TextInput
bind:value={passwordVerify}
label={$t('form.confirmPassword')}
required
type="password"
/>
</div>
{#if data.site_view.local_site.registration_mode == 'RequireApplication'}
<Material
rounding="2xl"
color="none"
class="bg-yellow-200/10 border border-yellow-500/30 text-yellow-900 dark:text-yellow-50"
>
<Icon
src={ExclamationTriangle}
size="32"
mini
class="inline-block rounded-lg bg-yellow-500 p-1 text-white clear-both float-left mr-2"
/>
{$t('form.signup.application.info')}
</Material>
{#if data.site_view.local_site.application_question}
<Markdown source={data.site_view.local_site.application_question} />
{/if}
<MarkdownEditor
label={$t('form.signup.application.label')}
required
bind:value={application}
/>
{/if}
{#if captchaRequired}
<SectionTitle class="block -mb-3 font-medium text-sm">
Captcha
</SectionTitle>
<Material rounding="2xl">
<div class="flex flex-col gap-4">
{#await getCaptcha()}
<Spinner width={32} />
{:then}
{#if captcha?.ok}
<img
src="data:image/png;base64,{captcha.ok.png}"
alt="Captcha"
class="w-max"
/>
<audio controls src={captchaAudio}></audio>
{:else}
<Material
class="flex gap-2 dark:text-yellow-200 text-yellow-800 bg-yellow-500/20"
>
<Icon src={QuestionMarkCircle} mini size="24" />
No captcha was returned
</Material>
{/if}
{:catch err}
<Material
padding="sm"
class="flex gap-2 dark:text-yellow-200 text-yellow-800 bg-yellow-500/20"
>
<Icon src={ExclamationCircle} mini size="24" />
{err}
</Material>
{/await}
<Button onclick={() => getCaptcha()} size="square-md">
<Icon src={ArrowPath} size="16" mini />
</Button>
<TextInput required bind:value={verifyCaptcha} />
</div>
</Material>
{/if}
<Checkbox bind:checked={nsfw}>{$t('form.profile.showNSFW')}</Checkbox>
<input type="dn" name="honeypot" bind:value={honeypot} class="hidden" />
<Button
submit
color="primary"
size="lg"
loading={submitting}
disabled={submitting}
class="mt-auto"
>
{$t('form.submit')}
</Button>
</Placeholder>
{:else}
<div class="my-auto">
<Placeholder
icon={XCircle}
title={$t('form.signup.closed.title')}
description={$t('form.signup.closed.description')}
>
<Button icon={Plus} href="/signup">
{$t('form.signup.closed.anotherInstance')}
</Button>
</Placeholder>
</div>
{/if}
</form>
{:else if stage == 'verify'}
<div class="flex-2/3 flex flex-col h-full justify-center gap-8">
<h2 class="font-medium text-3xl">{$t('toast.verifyEmail')}</h2>
<ErrorContainer scope={page.url.pathname} />
<form
onsubmit={e => {
e.preventDefault()
verifiedEmail()
}}
class="flex items-center gap-2"
>
<Button
loading={verifying}
disabled={verifying}
submit
color="primary"
rounding="pill"
class="self-start"
>
{$t('form.signup.verify.submit')}
</Button>
<Button href="/signup" rounding="pill">
<Icon src={ArrowLeft} size="16" micro />
{$t('common.back')}
</Button>
</form>
</div>
{/if}
</form>
<Material
color="uniform"
class="flex-1/3 overflow-auto max-h-full max-md:hidden"
rounding="2xl"
padding="none"
>
<SiteCard
admins={data.admins}
site={data.site_view}
taglines={data.taglines}
version={data.version}
class="w-full p-4"
/>
</Material>
</div>