feat: add errorcontainer to move error messages to a better place

This commit is contained in:
Xylight committed 2024-09-01 14:55:10 -07:00
1 parent 60004f03a7
commit e097df959b
3 files changed
+108 -18

No files matched your search

+16 -9
View File
@@ -21,6 +21,11 @@
import { t } from '$lib/translations'
import Header from '$lib/components/ui/layout/pages/Header.svelte'
import { errorMessage } from '$lib/lemmy/error'
import ErrorContainer, {
clearErrorScope,
pushError,
} from '$lib/components/error/ErrorContainer.svelte'
import { page } from '$app/stores'
let data = {
instance: DEFAULT_INSTANCE_URL,
@@ -33,6 +38,7 @@
async function logIn() {
data.loading = true
clearErrorScope($page.route.id)
try {
data.instance = data.instance.trim()
@@ -57,8 +63,8 @@
throw new Error('Invalid credentials')
}
} catch (error) {
toast({
content:
pushError({
message:
JSON.parse((error as any)?.body?.message ?? '{}')?.error ==
'incorrect_login'
? errorMessage(
@@ -68,7 +74,7 @@
: `_${data.attempts + 1}`)
)
: errorMessage(error),
type: 'error',
scope: $page.route.id!,
})
data.attempts++
}
@@ -82,7 +88,7 @@
<div class="max-w-xl w-full mx-auto h-max my-auto">
<form on:submit|preventDefault={logIn} class="flex flex-col gap-5">
<div class="flex flex-col gap-2">
<div class="flex flex-col">
<Header>{$t('account.login')}</Header>
{#if $site && mayBeIncompatible(MINIMUM_VERSION, $site.version.replace('v', ''))}
<Note>
@@ -92,6 +98,7 @@
})}
</Note>
{/if}
<ErrorContainer class="pt-2" scope={$page.route.id} />
</div>
<div class="flex flex-row w-full items-center gap-2">
<TextInput
@@ -147,18 +154,18 @@
>
{$t('account.login')}
</Button>
<hr class="dark:border-zinc-700" />
<div class="flex flex-row items-center gap-2">
<Button color="tertiary" href="/signup">
<hr class="border-slate-200 dark:border-zinc-800" />
<div class="flex flex-row items-center gap-2 overflow-auto *:flex-shrink-0">
<Button rounding="pill" color="ghost" href="/signup">
<Icon src={Identification} mini size="16" />
{$t('account.signup')}
</Button>
<Button color="tertiary" href="/login_reset">
<Button rounding="pill" color="ghost" href="/login_reset">
<Icon src={QuestionMarkCircle} mini size="16" />
{$t('form.forgotpassword')}
</Button>
{#if !LINKED_INSTANCE_URL}
<Button color="tertiary" href="/login/guest">
<Button rounding="pill" color="ghost" href="/login/guest">
<Icon src={UserCircle} mini size="16" />
{$t('account.guest')}
</Button>