feat: Update login screen
This commit is contained in:
1 parent
9007eb46d6
commit
c3fc860117
5 files changed
+114
-20
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "photon-lemmy",
|
"name": "photon-lemmy",
|
||||||
"version": "23.7.10",
|
"version": "23.7.12",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
|
|||||||
@@ -7,6 +7,9 @@
|
|||||||
export let value: string = ''
|
export let value: string = ''
|
||||||
export let maxlength: number = -1
|
export let maxlength: number = -1
|
||||||
export let required = false
|
export let required = false
|
||||||
|
export let id = ''
|
||||||
|
export let pattern: string | undefined = undefined
|
||||||
|
export let minlength: number = 0
|
||||||
|
|
||||||
function typeAction(node: Node) {
|
function typeAction(node: Node) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -33,11 +36,18 @@
|
|||||||
<input
|
<input
|
||||||
use:typeAction
|
use:typeAction
|
||||||
bind:value
|
bind:value
|
||||||
|
on:keydown={(e) => dispatcher('keydown', e)}
|
||||||
on:input={(e) => dispatcher('input', e)}
|
on:input={(e) => dispatcher('input', e)}
|
||||||
{placeholder}
|
{placeholder}
|
||||||
{maxlength}
|
{maxlength}
|
||||||
class="w-full px-3 text-sm py-2.5 bg-transparent border border-black/20
|
{minlength}
|
||||||
dark:border-white/20 dark:focus:border-white focus:outline-none
|
{pattern}
|
||||||
focus:border-black transition-colors rounded-md {clazz}"
|
{id}
|
||||||
|
class="{value.length != 0
|
||||||
|
? 'invalid:border-red-400'
|
||||||
|
: ''} w-full px-3 text-sm py-2.5 bg-transparent
|
||||||
|
border border-black/20 dark:border-white/20 dark:focus:border-white
|
||||||
|
focus:outline-none focus:border-black transition-colors rounded-md {clazz}"
|
||||||
|
{required}
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
@@ -43,7 +43,9 @@
|
|||||||
: ExclamationCircle}
|
: ExclamationCircle}
|
||||||
/>
|
/>
|
||||||
<div class="flex flex-col p-4 pl-0">
|
<div class="flex flex-col p-4 pl-0">
|
||||||
<h1 class="text-base font-bold">{toast.title}</h1>
|
{#if toast.title}
|
||||||
|
<h1 class="text-base font-bold">{toast.title}</h1>
|
||||||
|
{/if}
|
||||||
<p class="text-sm">{toast.content}</p>
|
<p class="text-sm">{toast.content}</p>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
|
|||||||
@@ -9,14 +9,51 @@ export enum ToastType {
|
|||||||
|
|
||||||
export interface Toast {
|
export interface Toast {
|
||||||
id: number
|
id: number
|
||||||
title: string
|
title: string | undefined
|
||||||
content: string
|
content: string
|
||||||
type: ToastType
|
type: ToastType
|
||||||
}
|
}
|
||||||
|
|
||||||
export const toasts = writable<Toast[]>([])
|
export const toasts = writable<Toast[]>([])
|
||||||
|
|
||||||
export function addToast(title: string, content: string, type: ToastType) {
|
export function toast({
|
||||||
|
title,
|
||||||
|
content,
|
||||||
|
type = ToastType.info,
|
||||||
|
}: {
|
||||||
|
title?: string
|
||||||
|
content: string
|
||||||
|
type: ToastType
|
||||||
|
}) {
|
||||||
|
let id = 0
|
||||||
|
|
||||||
|
toasts.update((toasts) => {
|
||||||
|
id = Math.floor(Math.random() * 10000)
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
id: id,
|
||||||
|
content: content,
|
||||||
|
title: title,
|
||||||
|
type: type,
|
||||||
|
},
|
||||||
|
...toasts,
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
toasts.update((toasts) => toasts.filter((toast) => toast.id != id))
|
||||||
|
}, 5000)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated use @function toast
|
||||||
|
*/
|
||||||
|
export function addToast(
|
||||||
|
title: string | undefined,
|
||||||
|
content: string,
|
||||||
|
type: ToastType
|
||||||
|
) {
|
||||||
let id = 0
|
let id = 0
|
||||||
|
|
||||||
toasts.update((toasts) => {
|
toasts.update((toasts) => {
|
||||||
|
|||||||
@@ -3,14 +3,19 @@
|
|||||||
import Button from '$lib/components/input/Button.svelte'
|
import Button from '$lib/components/input/Button.svelte'
|
||||||
import TextInput from '$lib/components/input/TextInput.svelte'
|
import TextInput from '$lib/components/input/TextInput.svelte'
|
||||||
import Card from '$lib/components/ui/Card.svelte'
|
import Card from '$lib/components/ui/Card.svelte'
|
||||||
import { ToastType, addToast } from '$lib/components/ui/toasts/toasts.js'
|
import {
|
||||||
|
ToastType,
|
||||||
|
addToast,
|
||||||
|
toast,
|
||||||
|
} from '$lib/components/ui/toasts/toasts.js'
|
||||||
import { DEFAULT_INSTANCE_URL, authData, getClient } from '$lib/lemmy.js'
|
import { DEFAULT_INSTANCE_URL, authData, getClient } from '$lib/lemmy.js'
|
||||||
import { Color } from '$lib/ui/colors.js'
|
import { Color } from '$lib/ui/colors.js'
|
||||||
|
|
||||||
let data = {
|
let data = {
|
||||||
instance: DEFAULT_INSTANCE_URL,
|
instance: '',
|
||||||
username: '',
|
username: '',
|
||||||
password: '',
|
password: '',
|
||||||
|
totp: '',
|
||||||
loading: false,
|
loading: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,6 +41,7 @@
|
|||||||
const response = await getClient(data.instance).login({
|
const response = await getClient(data.instance).login({
|
||||||
username_or_email: data.username,
|
username_or_email: data.username,
|
||||||
password: data.password,
|
password: data.password,
|
||||||
|
totp_2fa_token: data.totp,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (response?.jwt) {
|
if (response?.jwt) {
|
||||||
@@ -45,13 +51,16 @@
|
|||||||
username: data.username,
|
username: data.username,
|
||||||
})
|
})
|
||||||
|
|
||||||
addToast('Success', 'Successfully logged in.', ToastType.success)
|
toast({ content: 'Successfully logged in.', type: ToastType.success })
|
||||||
goto('/')
|
goto('/')
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid credentials')
|
throw new Error('Invalid credentials')
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
addToast('Error', error as any, ToastType.error)
|
toast({
|
||||||
|
content: error as any,
|
||||||
|
type: ToastType.error,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
data.loading = false
|
data.loading = false
|
||||||
}
|
}
|
||||||
@@ -59,20 +68,55 @@
|
|||||||
|
|
||||||
<svelte:head>Login</svelte:head>
|
<svelte:head>Login</svelte:head>
|
||||||
|
|
||||||
<Card class="mx-auto p-6 max-w-lg">
|
<!-- <div
|
||||||
|
class="p-4 absolute top-[50%] left-[50%] translate-x-[-50%]
|
||||||
|
translate-y-[-50%] w-full flex flex-col items-center justify-center"
|
||||||
|
> -->
|
||||||
|
<Card class="p-6 max-w-lg w-full mx-auto">
|
||||||
<form on:submit|preventDefault={logIn} class="flex flex-col gap-4">
|
<form on:submit|preventDefault={logIn} class="flex flex-col gap-4">
|
||||||
<h1 class="font-bold text-lg">Log in</h1>
|
<h1 class="font-bold text-2xl">Log in</h1>
|
||||||
|
<div class="flex flex-row w-full items-center gap-2">
|
||||||
|
<TextInput
|
||||||
|
id="username"
|
||||||
|
bind:value={data.username}
|
||||||
|
label="Username"
|
||||||
|
placeholder="Example"
|
||||||
|
class="flex-1"
|
||||||
|
on:input={(e) => {
|
||||||
|
if (e.detail.data == '@') {
|
||||||
|
document.getElementById('instance_url')?.focus()
|
||||||
|
data.username = data.username.replace('@', '')
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<span class="mt-5 font-bold">@</span>
|
||||||
|
<TextInput
|
||||||
|
id="instance_url"
|
||||||
|
label="Instance URL"
|
||||||
|
placeholder={DEFAULT_INSTANCE_URL}
|
||||||
|
bind:value={data.instance}
|
||||||
|
class="flex-1"
|
||||||
|
required
|
||||||
|
pattern={'(?!-)[A-Za-z0-9-]+([-.]{1}[a-z0-9]+)*.[A-Za-z]{2,6}'}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<TextInput
|
<TextInput
|
||||||
bind:value={data.instance}
|
id="password"
|
||||||
label="Instance URL"
|
bind:value={data.password}
|
||||||
placeholder="lemmy.world"
|
label="Password"
|
||||||
|
type="password"
|
||||||
|
required
|
||||||
/>
|
/>
|
||||||
<TextInput
|
<TextInput
|
||||||
bind:value={data.username}
|
id="totp"
|
||||||
label="Username"
|
bind:value={data.totp}
|
||||||
placeholder="Example"
|
label="2FA Code"
|
||||||
|
placeholder="123456"
|
||||||
|
pattern={'\\d{6}'}
|
||||||
|
minlength={6}
|
||||||
|
maxlength={6}
|
||||||
/>
|
/>
|
||||||
<TextInput bind:value={data.password} label="Password" type="password" />
|
|
||||||
<Button
|
<Button
|
||||||
loading={data.loading}
|
loading={data.loading}
|
||||||
disabled={data.loading}
|
disabled={data.loading}
|
||||||
@@ -84,3 +128,4 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</Card>
|
</Card>
|
||||||
|
<!-- </div> -->
|
||||||
Reference in new issue
Block a user