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
+238 -69

No files matched your search

+17 -4
View File
@@ -15,6 +15,8 @@
} }
initialOffset?: number initialOffset?: number
debounceResize?: number debounceResize?: number
useWindow?: boolean
height?: number
} }
let { let {
@@ -25,6 +27,8 @@
initialOffset = 0, initialOffset = 0,
restore = $bindable(), restore = $bindable(),
debounceResize = 100, debounceResize = 100,
useWindow = true,
height = 0,
...rest ...rest
}: Props = $props() }: Props = $props()
@@ -177,15 +181,24 @@
}) })
</script> </script>
<svelte:window bind:scrollY /> <svelte:window
bind:scrollY={
() => (useWindow ? scrollY : 0),
v => {
if (useWindow) scrollY = v
}
}
/>
<div <div
bind:this={virtualListEl} bind:this={virtualListEl}
style="position: relative; height: {cumulativeItemHeights[ style="position: relative; height: {height ||
visibleItems?.[visibleItems.length - 1]?.index cumulativeItemHeights[visibleItems?.[visibleItems.length - 1]?.index]}px;"
]}px;"
{...rest} {...rest}
id="feed" id="feed"
onscroll={() => {
if (!useWindow) scrollY = virtualListEl?.scrollTop ?? 0
}}
> >
<div <div
style="height: {cumulativeItemHeights[visibleItems?.[0]?.index - 1] || style="height: {cumulativeItemHeights[visibleItems?.[0]?.index - 1] ||
+1 -1
View File
@@ -64,7 +64,7 @@
style: 'grid-area: sidebar; width: 100% !important;', style: 'grid-area: sidebar; width: 100% !important;',
})} })}
{@render main?.({ {@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', style: 'grid-area: main',
})} })}
{@render suffix?.({ {@render suffix?.({
+22 -6
View File
@@ -20,6 +20,8 @@
} from 'mono-svelte' } from 'mono-svelte'
import type { Placement } from 'svelte-floating-ui/core' import type { Placement } from 'svelte-floating-ui/core'
import { import {
ArrowDown,
ArrowLeftOnRectangle,
Bars3, Bars3,
Bookmark, Bookmark,
BugAnt, BugAnt,
@@ -27,6 +29,7 @@
Cog6Tooth, Cog6Tooth,
ComputerDesktop, ComputerDesktop,
Icon, Icon,
Identification,
Inbox, Inbox,
Moon, Moon,
ServerStack, ServerStack,
@@ -91,13 +94,13 @@
{#if profile.data?.jwt} {#if profile.data?.jwt}
<MenuButton href="/profile"> <MenuButton href="/profile">
{#snippet prefix()} {#snippet prefix()}
<Icon src={UserCircle} micro width={16} /> <Icon src={UserCircle} micro size="16" />
{/snippet} {/snippet}
{$t('profile.profile')} {$t('profile.profile')}
</MenuButton> </MenuButton>
<MenuButton href="/inbox"> <MenuButton href="/inbox">
{#snippet prefix()} {#snippet prefix()}
<Icon src={Inbox} micro width={16} /> <Icon src={Inbox} micro size="16" />
{/snippet} {/snippet}
{$t('profile.inbox')} {$t('profile.inbox')}
{#if $notifications.inbox > 0} {#if $notifications.inbox > 0}
@@ -108,21 +111,34 @@
</MenuButton> </MenuButton>
<MenuButton href="/saved"> <MenuButton href="/saved">
{#snippet prefix()} {#snippet prefix()}
<Icon src={Bookmark} micro width={16} /> <Icon src={Bookmark} micro size="16" />
{/snippet} {/snippet}
{$t('profile.saved')} {$t('profile.saved')}
</MenuButton> </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} {/if}
<MenuButton href="/accounts"> <MenuButton href="/accounts">
{#snippet prefix()} {#snippet prefix()}
<Icon src={UserGroup} micro width={16} /> <Icon src={UserGroup} micro size="16" />
{/snippet} {/snippet}
{$t('account.accounts')} {$t('account.accounts')}
</MenuButton> </MenuButton>
<MenuDivider>{$t('nav.menu.app')}</MenuDivider> <MenuDivider>{$t('nav.menu.app')}</MenuDivider>
<MenuButton href="/settings"> <MenuButton href="/settings">
{#snippet prefix()} {#snippet prefix()}
<Icon src={Cog6Tooth} micro width={16} /> <Icon src={Cog6Tooth} micro size="16" />
{/snippet} {/snippet}
{$t('nav.menu.settings')} {$t('nav.menu.settings')}
</MenuButton> </MenuButton>
@@ -166,7 +182,7 @@
{#if settings.debugInfo} {#if settings.debugInfo}
<MenuButton href="/util"> <MenuButton href="/util">
{#snippet prefix()} {#snippet prefix()}
<Icon src={BugAnt} mini width={16} /> <Icon src={BugAnt} mini size="16" />
{/snippet} {/snippet}
Debug Debug
</MenuButton> </MenuButton>
+11 -5
View File
@@ -189,6 +189,12 @@
"title": "Registrations closed", "title": "Registrations closed",
"description": "This instance has registrations closed. Find another instance.", "description": "This instance has registrations closed. Find another instance.",
"anotherInstance": "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", "description": "Description",
@@ -927,14 +933,14 @@
"incorrect_login": "Incorrect login credentials. Please try again.", "incorrect_login": "Incorrect login credentials. Please try again.",
"incorrect_login_2": "Incorrect login credentials. Try again.", "incorrect_login_2": "Incorrect login credentials. Try again.",
"incorrect_login_3": "Incorrect, again. Try a few more times.", "incorrect_login_3": "Incorrect, again. Try a few more times.",
"incorrect_login_4": "Those still aren't the right credentials. Keep trying.", "incorrect_login_4": "Successfully logged-wait no. Incorrect credentials.",
"incorrect_login_5": "I swear, you need to look at the keys you're pressing.", "incorrect_login_5": "Look at your keyboard while typing this time.",
"incorrect_login_6": "Is this a joke to you?", "incorrect_login_6": "I believe in you.",
"incorrect_login_7": "Either you struggle with typing or you're harassing me at this point.", "incorrect_login_7": "Okay, you're messing with me now.",
"incorrect_login_8": "I give up.", "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_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_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": "...", "incorrect_login_12": "...",
"registration_application_is_pending": "The registration application for that account hasn't been accepted yet.", "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.", "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, ChevronUp,
EllipsisHorizontal, EllipsisHorizontal,
Icon, Icon,
Identification,
Plus, Plus,
QuestionMarkCircle, QuestionMarkCircle,
} from 'svelte-hero-icons' } from 'svelte-hero-icons'
@@ -119,6 +120,12 @@
{/snippet} {/snippet}
{$t('account.login')} {$t('account.login')}
</Button> </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} {#if !LINKED_INSTANCE_URL}
<Button href="/accounts/login/guest" rounding="pill"> <Button href="/accounts/login/guest" rounding="pill">
{#snippet prefix()} {#snippet prefix()}
@@ -177,7 +184,7 @@
size="custom" size="custom"
class="absolute top-0 right-0 w-6 h-6 m-1" class="absolute top-0 right-0 w-6 h-6 m-1"
color="tertiary" color="tertiary"
aria-label={$t('post.actions.more')} aria-label={$t('post.actions.more.label')}
> >
{#snippet prefix()} {#snippet prefix()}
<Icon src={EllipsisHorizontal} mini size="16" /> <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>
+26 -22
View File
@@ -17,13 +17,15 @@
import { preventDefault } from 'svelte/legacy' import { preventDefault } from 'svelte/legacy'
import { goto } from '$app/navigation' import { goto } from '$app/navigation'
import VirtualList from '$lib/components/render/VirtualList.svelte'
import Avatar from '$lib/components/ui/Avatar.svelte' import Avatar from '$lib/components/ui/Avatar.svelte'
import Header from '$lib/components/ui/layout/pages/Header.svelte' import Header from '$lib/components/ui/layout/pages/Header.svelte'
import { t } from '$lib/i18n/translations' import { t } from '$lib/i18n/translations'
import { DEFAULT_INSTANCE_URL } from '$lib/instance.svelte.js' import { DEFAULT_INSTANCE_URL } from '$lib/instance.svelte.js'
import { validateInstance } from '$lib/lemmy.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 { onMount } from 'svelte'
import { ArrowLeft, Icon } from 'svelte-hero-icons'
let selectedInstance: string = $state('') let selectedInstance: string = $state('')
let validating: boolean = $state(false) let validating: boolean = $state(false)
@@ -65,49 +67,51 @@
</svelte:head> </svelte:head>
<div class="mx-auto max-w-xl flex flex-col gap-4 my-auto h-max w-full"> <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> <Header>{$t('form.signup.title')}</Header>
<p>{$t('form.signup.description')}</p> <p>{$t('form.signup.description')}</p>
<p> <p>
{$t('form.signup.info')} {$t('form.signup.info')}
</p> </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} {#if instances}
{#each instances as instance (instance)} <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"
>
{#snippet item(i)}
<button <button
onclick={() => (selectedInstance = instance.baseurl ?? '')} onclick={() => (selectedInstance = instances![i].baseurl ?? '')}
class="flex flex-row gap-2 text-left py-2 first:pt-0 last:pb-0 items-center 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" 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 <Avatar
width={32} width={32}
url={instance.icon} url={instances![i].icon}
alt={instance.name} alt={instances![i].name}
class="shrink-0" class="shrink-0"
/> />
<div class="flex flex-col max-h-full w-full"> <div class="flex flex-col max-h-full w-full">
<span <span class="font-medium text-base whitespace-nowrap text-ellipsis">
class="font-medium text-base whitespace-nowrap text-ellipsis" {instances![i].name}
>
{instance.name}
</span> </span>
<span <span
class="whitespace-nowrap text-ellipsis overflow-hidden w-full" class="whitespace-nowrap text-ellipsis overflow-hidden w-full"
> >
{instance.desc} {instances![i].desc}
</span> </span>
</div> </div>
</button> </button>
{/each} {/snippet}
{:else} </VirtualList>
<div class="mx-auto my-auto self-center justify-self-center">
<Spinner width={32} />
</div>
{/if} {/if}
</div>
</Material>
<form <form
class="flex flex-col gap-4" class="flex flex-col gap-4"
onsubmit={preventDefault(async () => { onsubmit={preventDefault(async () => {
+140 -30
View File
@@ -13,6 +13,7 @@
import type { GetCaptchaResponse } from 'lemmy-js-client' import type { GetCaptchaResponse } from 'lemmy-js-client'
import { Button, TextInput } from 'mono-svelte' import { Button, TextInput } from 'mono-svelte'
import { import {
ArrowLeft,
ArrowPath, ArrowPath,
ExclamationCircle, ExclamationCircle,
ExclamationTriangle, ExclamationTriangle,
@@ -23,13 +24,20 @@
} from 'svelte-hero-icons' } from 'svelte-hero-icons'
import Header from '$lib/components/ui/layout/pages/Header.svelte' import Header from '$lib/components/ui/layout/pages/Header.svelte'
import { t } from '$lib/i18n/translations.js' 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 { data } = $props()
let stage = $state<'signup' | 'verify' | 'application'>('signup')
const instance = page.params.instance const instance = page.params.instance
let captchaRequired = data.site_view.local_site.captcha_enabled let captchaRequired = data.site_view.local_site.captcha_enabled
let email: string | undefined = $state('') let email: string | undefined = $state('')
$effect(() => { $effect(() => {
@@ -44,7 +52,8 @@
application: string = $state(''), application: string = $state(''),
submitting: boolean = $state(false), submitting: boolean = $state(false),
honeypot: string | undefined = $state(undefined), honeypot: string | undefined = $state(undefined),
nsfw: boolean = $state(false) nsfw: boolean = $state(false),
verifying: boolean = $state(false)
const getCaptcha = async () => const getCaptcha = async () =>
(captcha = await getClient(instance, fetch).getCaptcha()) (captcha = await getClient(instance, fetch).getCaptcha())
@@ -54,6 +63,7 @@
) )
async function submit() { async function submit() {
clearErrorScope(page.url.pathname)
submitting = true submitting = true
try { try {
@@ -69,30 +79,25 @@
honeypot, honeypot,
}) })
const registrationMode = data.site_view.local_site.registration_mode
if (res?.jwt) { 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' }) toast({ content: $t('toast.logIn'), type: 'success' })
goto('/') goto('/')
} else if ( } else if (
res.verify_email_sent || res.verify_email_sent ||
data.site_view.local_site.registration_mode == 'RequireApplication' registrationMode == 'RequireApplication'
) { ) {
if (res.verify_email_sent) { if (res.verify_email_sent) return (stage = 'verify')
toast({
content: $t('toast.verifyEmail'), if (registrationMode == 'RequireApplication') {
type: 'info', return toast({
})
}
if (
data.site_view.local_site.registration_mode == 'RequireApplication'
) {
toast({
content: $t('toast.waitApplication'), content: $t('toast.waitApplication'),
type: 'info', type: 'info',
}) })
} }
goto('/')
} else { } else {
throw new Error($t('toast.failSignup')) throw new Error($t('toast.failSignup'))
} }
@@ -102,39 +107,89 @@
type: 'success', type: 'success',
}) })
} catch (err) { } catch (err) {
toast({ pushError({
content: err as string, scope: page.url.pathname,
type: 'error', message: errorMessage(err as string),
}) })
} }
submitting = false 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> </script>
<svelte:head> <svelte:head>
<title>Sign up</title> <title>{$t('account.signup')}</title>
</svelte:head> </svelte:head>
<div class="flex flex-col md:flex-row flex-1/3 gap-8 h-full max-w-5xl mx-auto">
{#if stage == 'signup'}
<form <form
class="flex flex-col gap-4 max-w-2xl mx-auto h-full w-full" class="flex flex-col gap-4 h-full w-full flex-2/3"
onsubmit={preventDefault(submit)} onsubmit={preventDefault(submit)}
> >
<span class="flex gap-4 items-center font-bold text-xl text-center mx-auto"> <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} {#if data.site_view.site.icon}
<Avatar circle={false} width={48} url={data.site_view.site.icon} /> <Avatar
circle={false}
width={48}
url={data.site_view.site.icon}
/>
{/if} {/if}
{data.site_view.site.name} {data.site_view.site.name}
</span> </span>
{/snippet}
</Header>
{#if data.site_view.local_site.registration_mode != 'Closed'} {#if data.site_view.local_site.registration_mode != 'Closed'}
<Header>{$t('form.signup.title')}</Header> <div class="flex flex-col md:flex-row gap-2 *:flex-1">
<TextInput <TextInput
bind:value={email} bind:value={email}
label={$t('form.email')} label={$t('form.email')}
required={data.site_view.local_site.require_email_verification} required={data.site_view.local_site.require_email_verification}
type="email" type="email"
/> />
<TextInput bind:value={username} label={$t('form.username')} required /> <TextInput
bind:value={username}
label={$t('form.username')}
required
/>
</div>
<div class="flex flex-col md:flex-row gap-2 *:flex-1">
<TextInput <TextInput
bind:value={password} bind:value={password}
label={$t('form.password')} label={$t('form.password')}
@@ -147,9 +202,19 @@
required required
type="password" type="password"
/> />
</div>
{#if data.site_view.local_site.registration_mode == 'RequireApplication'} {#if data.site_view.local_site.registration_mode == 'RequireApplication'}
<Material class="dark:text-yellow-200 text-yellow-800 bg-yellow-500/20"> <Material
<Icon src={ExclamationTriangle} mini size="20" /> 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')} {$t('form.signup.application.info')}
</Material> </Material>
{#if data.site_view.local_site.application_question} {#if data.site_view.local_site.application_question}
@@ -162,8 +227,10 @@
/> />
{/if} {/if}
{#if captchaRequired} {#if captchaRequired}
<div> <SectionTitle class="block -mb-3 font-medium text-sm">
<div class="block my-1 font-bold text-sm">Captcha</div> Captcha
</SectionTitle>
<Material rounding="2xl">
<div class="flex flex-col gap-4"> <div class="flex flex-col gap-4">
{#await getCaptcha()} {#await getCaptcha()}
<Spinner width={32} /> <Spinner width={32} />
@@ -197,7 +264,7 @@
</Button> </Button>
<TextInput required bind:value={verifyCaptcha} /> <TextInput required bind:value={verifyCaptcha} />
</div> </div>
</div> </Material>
{/if} {/if}
<Checkbox bind:checked={nsfw}>{$t('form.profile.showNSFW')}</Checkbox> <Checkbox bind:checked={nsfw}>{$t('form.profile.showNSFW')}</Checkbox>
<input type="dn" name="honeypot" bind:value={honeypot} class="hidden" /> <input type="dn" name="honeypot" bind:value={honeypot} class="hidden" />
@@ -225,3 +292,46 @@
</div> </div>
{/if} {/if}
</form> </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}
<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>