From 8dd734fc24f80b267b78995504691eb22c581e00 Mon Sep 17 00:00:00 2001 From: James Xylight Date: Fri, 11 Jul 2025 12:31:17 -0700 Subject: [PATCH] impr: make signup page more user friendly --- src/lib/components/render/VirtualList.svelte | 21 +- src/lib/components/ui/layout/Shell.svelte | 2 +- src/lib/components/ui/navbar/Profile.svelte | 28 +- src/lib/i18n/en.json | 16 +- src/routes/accounts/+page.svelte | 9 +- src/routes/signup/+layout.svelte | 13 + src/routes/signup/+page.svelte | 80 ++-- src/routes/signup/[instance]/+page.svelte | 362 ++++++++++++------- 8 files changed, 350 insertions(+), 181 deletions(-) create mode 100644 src/routes/signup/+layout.svelte diff --git a/src/lib/components/render/VirtualList.svelte b/src/lib/components/render/VirtualList.svelte index 5b1bf997..6a207985 100644 --- a/src/lib/components/render/VirtualList.svelte +++ b/src/lib/components/render/VirtualList.svelte @@ -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 @@ }) - + (useWindow ? scrollY : 0), + v => { + if (useWindow) scrollY = v + } + } +/>
{ + if (!useWindow) scrollY = virtualListEl?.scrollTop ?? 0 + }} >
{#snippet prefix()} - + {/snippet} {$t('profile.profile')} {#snippet prefix()} - + {/snippet} {$t('profile.inbox')} {#if $notifications.inbox > 0} @@ -108,21 +111,34 @@ {#snippet prefix()} - + {/snippet} {$t('profile.saved')} + {:else} + + {#snippet prefix()} + + {/snippet} + {$t('account.login')} + + + {#snippet prefix()} + + {/snippet} + {$t('account.signup')} + {/if} {#snippet prefix()} - + {/snippet} {$t('account.accounts')} {$t('nav.menu.app')} {#snippet prefix()} - + {/snippet} {$t('nav.menu.settings')} @@ -166,7 +182,7 @@ {#if settings.debugInfo} {#snippet prefix()} - + {/snippet} Debug diff --git a/src/lib/i18n/en.json b/src/lib/i18n/en.json index 39c3c593..f1fc73f9 100644 --- a/src/lib/i18n/en.json +++ b/src/lib/i18n/en.json @@ -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.", diff --git a/src/routes/accounts/+page.svelte b/src/routes/accounts/+page.svelte index 0b9e083c..839a7f23 100644 --- a/src/routes/accounts/+page.svelte +++ b/src/routes/accounts/+page.svelte @@ -23,6 +23,7 @@ ChevronUp, EllipsisHorizontal, Icon, + Identification, Plus, QuestionMarkCircle, } from 'svelte-hero-icons' @@ -119,6 +120,12 @@ {/snippet} {$t('account.login')} + {#if !LINKED_INSTANCE_URL}
{$t('form.signup.title')}

{$t('form.signup.description')}

{$t('form.signup.info')}

- -
- {#if instances} - {#each instances as instance (instance)} - - {/each} - {:else} -
- -
- {/if} -
-
+ {#snippet item(i)} + + {/snippet} + + {/if}
{ diff --git a/src/routes/signup/[instance]/+page.svelte b/src/routes/signup/[instance]/+page.svelte index 8dae606f..ab1cfe07 100644 --- a/src/routes/signup/[instance]/+page.svelte +++ b/src/routes/signup/[instance]/+page.svelte @@ -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 + } - Sign up + {$t('account.signup')} - - - {#if data.site_view.site.icon} - - {/if} - {data.site_view.site.name} - - - {#if data.site_view.local_site.registration_mode != 'Closed'} -
{$t('form.signup.title')}
- - - - - {#if data.site_view.local_site.registration_mode == 'RequireApplication'} - - - {$t('form.signup.application.info')} - - {#if data.site_view.local_site.application_question} - - {/if} - - {/if} - {#if captchaRequired} -
-
Captcha
-
- {#await getCaptcha()} - - {:then} - {#if captcha?.ok} - Captcha - - {:else} - - - No captcha was returned - - {/if} - {:catch err} - - - {err} - - {/await} - - -
-
- {/if} - {$t('form.profile.showNSFW')} - - - {:else} -
- - +
+ {$t('form.signup.title')} + {#snippet extended()} + + {#if data.site_view.site.icon} + + {/if} + {data.site_view.site.name} + + {/snippet} +
+ + {#if data.site_view.local_site.registration_mode != 'Closed'} +
+ + +
+
+ + +
+ {#if data.site_view.local_site.registration_mode == 'RequireApplication'} + + + {$t('form.signup.application.info')} + + {#if data.site_view.local_site.application_question} + + {/if} + + {/if} + {#if captchaRequired} + + Captcha + + +
+ {#await getCaptcha()} + + {:then} + {#if captcha?.ok} + Captcha + + {:else} + + + No captcha was returned + + {/if} + {:catch err} + + + {err} + + {/await} + + +
+
+ {/if} + {$t('form.profile.showNSFW')} + + -
+ {:else} +
+ + + +
+ {/if} + + {:else if stage == 'verify'} +
+

{$t('toast.verifyEmail')}

+ +
{ + e.preventDefault() + verifiedEmail() + }} + class="flex items-center gap-2" + > + + +
{/if} - + + + +