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

+17 -4
View File
@@ -15,6 +15,8 @@
}
initialOffset?: number
debounceResize?: number
useWindow?: boolean
height?: number
}
let {
@@ -25,6 +27,8 @@
initialOffset = 0,
restore = $bindable(),
debounceResize = 100,
useWindow = true,
height = 0,
...rest
}: Props = $props()
@@ -177,15 +181,24 @@
})
</script>
<svelte:window bind:scrollY />
<svelte:window
bind:scrollY={
() => (useWindow ? scrollY : 0),
v => {
if (useWindow) scrollY = v
}
}
/>
<div
bind:this={virtualListEl}
style="position: relative; height: {cumulativeItemHeights[
visibleItems?.[visibleItems.length - 1]?.index
]}px;"
style="position: relative; height: {height ||
cumulativeItemHeights[visibleItems?.[visibleItems.length - 1]?.index]}px;"
{...rest}
id="feed"
onscroll={() => {
if (!useWindow) scrollY = virtualListEl?.scrollTop ?? 0
}}
>
<div
style="height: {cumulativeItemHeights[visibleItems?.[0]?.index - 1] ||
+1 -1
View File
@@ -64,7 +64,7 @@
style: 'grid-area: sidebar; width: 100% !important;',
})}
{@render main?.({
class: `w-full bg-slate-25 dark:bg-zinc-925 justify-self-center shadow-xs z-0 main pb-22 lg:pb-0 lg:pt-20!`,
class: `w-full bg-slate-25 dark:bg-zinc-925 justify-self-center shadow-xs main pb-22 lg:pt-20! pb-4 sm:pb-6`,
style: 'grid-area: main',
})}
{@render suffix?.({
+22 -6
View File
@@ -20,6 +20,8 @@
} from 'mono-svelte'
import type { Placement } from 'svelte-floating-ui/core'
import {
ArrowDown,
ArrowLeftOnRectangle,
Bars3,
Bookmark,
BugAnt,
@@ -27,6 +29,7 @@
Cog6Tooth,
ComputerDesktop,
Icon,
Identification,
Inbox,
Moon,
ServerStack,
@@ -91,13 +94,13 @@
{#if profile.data?.jwt}
<MenuButton href="/profile">
{#snippet prefix()}
<Icon src={UserCircle} micro width={16} />
<Icon src={UserCircle} micro size="16" />
{/snippet}
{$t('profile.profile')}
</MenuButton>
<MenuButton href="/inbox">
{#snippet prefix()}
<Icon src={Inbox} micro width={16} />
<Icon src={Inbox} micro size="16" />
{/snippet}
{$t('profile.inbox')}
{#if $notifications.inbox > 0}
@@ -108,21 +111,34 @@
</MenuButton>
<MenuButton href="/saved">
{#snippet prefix()}
<Icon src={Bookmark} micro width={16} />
<Icon src={Bookmark} micro size="16" />
{/snippet}
{$t('profile.saved')}
</MenuButton>
{:else}
<MenuButton href="/accounts/login">
{#snippet prefix()}
<Icon src={ArrowLeftOnRectangle} mini size="16" />
{/snippet}
{$t('account.login')}
</MenuButton>
<MenuButton href="/signup">
{#snippet prefix()}
<Icon src={Identification} micro size="16" />
{/snippet}
{$t('account.signup')}
</MenuButton>
{/if}
<MenuButton href="/accounts">
{#snippet prefix()}
<Icon src={UserGroup} micro width={16} />
<Icon src={UserGroup} micro size="16" />
{/snippet}
{$t('account.accounts')}
</MenuButton>
<MenuDivider>{$t('nav.menu.app')}</MenuDivider>
<MenuButton href="/settings">
{#snippet prefix()}
<Icon src={Cog6Tooth} micro width={16} />
<Icon src={Cog6Tooth} micro size="16" />
{/snippet}
{$t('nav.menu.settings')}
</MenuButton>
@@ -166,7 +182,7 @@
{#if settings.debugInfo}
<MenuButton href="/util">
{#snippet prefix()}
<Icon src={BugAnt} mini width={16} />
<Icon src={BugAnt} mini size="16" />
{/snippet}
Debug
</MenuButton>
+11 -5
View File
@@ -189,6 +189,12 @@
"title": "Registrations closed",
"description": "This instance has registrations closed. Find another instance.",
"anotherInstance": "Find another instance"
},
"verify": {
"title": "Verify email",
"description": "Check your inbox for a verification link. Once you've clicked it, press the button below.",
"submit": "I've verified my email",
"error": "Your email has not been verified."
}
},
"description": "Description",
@@ -927,14 +933,14 @@
"incorrect_login": "Incorrect login credentials. Please try again.",
"incorrect_login_2": "Incorrect login credentials. Try again.",
"incorrect_login_3": "Incorrect, again. Try a few more times.",
"incorrect_login_4": "Those still aren't the right credentials. Keep trying.",
"incorrect_login_5": "I swear, you need to look at the keys you're pressing.",
"incorrect_login_6": "Is this a joke to you?",
"incorrect_login_7": "Either you struggle with typing or you're harassing me at this point.",
"incorrect_login_4": "Successfully logged-wait no. Incorrect credentials.",
"incorrect_login_5": "Look at your keyboard while typing this time.",
"incorrect_login_6": "I believe in you.",
"incorrect_login_7": "Okay, you're messing with me now.",
"incorrect_login_8": "I give up.",
"incorrect_login_9": "Each of these requests you make are sending data through via an incredible technology. And you're using it to make failed logins.",
"incorrect_login_10": "Think about this. The poor instance admins have to maintain their server just for you to make these useless requests.",
"incorrect_login_11": "I give up, for real this time.",
"incorrect_login_11": "Each press of the button uses thousands of CPU cycles to process your request, which ends up failing.",
"incorrect_login_12": "...",
"registration_application_is_pending": "The registration application for that account hasn't been accepted yet.",
"couldnt_find_post": "That post doesn't exist, isn't on this instance, or was removed.",
+8 -1
View File
@@ -23,6 +23,7 @@
ChevronUp,
EllipsisHorizontal,
Icon,
Identification,
Plus,
QuestionMarkCircle,
} from 'svelte-hero-icons'
@@ -119,6 +120,12 @@
{/snippet}
{$t('account.login')}
</Button>
<Button href="/signup" rounding="pill" class="px-4">
{#snippet prefix()}
<Icon src={Identification} size="16" mini />
{/snippet}
{$t('account.signup')}
</Button>
{#if !LINKED_INSTANCE_URL}
<Button href="/accounts/login/guest" rounding="pill">
{#snippet prefix()}
@@ -177,7 +184,7 @@
size="custom"
class="absolute top-0 right-0 w-6 h-6 m-1"
color="tertiary"
aria-label={$t('post.actions.more')}
aria-label={$t('post.actions.more.label')}
>
{#snippet prefix()}
<Icon src={EllipsisHorizontal} mini size="16" />
+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>