design: use better credentials tabs layout
This commit is contained in:
9 files changed
+185
-189
No files matched your search
@@ -1,4 +1,6 @@
|
||||
<script lang="ts">
|
||||
import TabButton from './switch/TabButton.svelte'
|
||||
|
||||
type T = $$Generic
|
||||
|
||||
interface Props {
|
||||
@@ -29,22 +31,14 @@
|
||||
>
|
||||
{#each options as option, index}
|
||||
{@const slctd = selected == option}
|
||||
<button
|
||||
class={[
|
||||
'px-2.5 py-1 rounded-xl text-sm font-medium transition-colors duration-75 relative cursor-pointer',
|
||||
slctd
|
||||
? 'bg-primary-900 dark:bg-primary-100 text-slate-50 dark:text-zinc-900 hover:brightness-90 active:brightness-75'
|
||||
: ' border dark:bg-zinc-900/50 bg-white border-slate-200 dark:border-zinc-800 hover:bg-slate-100 hover:dark:bg-zinc-800 active:bg-slate-200 active:dark:bg-zinc-900',
|
||||
]}
|
||||
onclick={e => {
|
||||
e.preventDefault()
|
||||
selected = option
|
||||
}}
|
||||
disabled={disabled[index] ?? false}
|
||||
<TabButton
|
||||
selected={slctd}
|
||||
onselect={() => (selected = option)}
|
||||
disabled={disabled[index]}
|
||||
type="button"
|
||||
>
|
||||
{optionNames[index] || option}
|
||||
</button>
|
||||
</TabButton>
|
||||
{/each}
|
||||
</div>
|
||||
{@render children?.({ selected })}
|
||||
@@ -0,0 +1,35 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte'
|
||||
import type { HTMLButtonAttributes } from 'svelte/elements'
|
||||
|
||||
interface Props extends HTMLButtonAttributes {
|
||||
selected?: boolean
|
||||
children: Snippet
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
let {
|
||||
selected = false,
|
||||
onselect,
|
||||
disabled,
|
||||
children,
|
||||
href,
|
||||
...rest
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
<svelte:element
|
||||
this={href ? 'a' : 'button'}
|
||||
class={[
|
||||
'px-2.5 py-1 rounded-xl text-sm font-medium transition-colors duration-75 relative cursor-pointer',
|
||||
selected
|
||||
? 'bg-primary-900 dark:bg-primary-100 text-slate-50 dark:text-zinc-900 hover:brightness-90 active:brightness-75'
|
||||
: ' border dark:bg-zinc-900/50 bg-white border-slate-200 dark:border-zinc-800 hover:bg-slate-100 hover:dark:bg-zinc-800 active:bg-slate-200 active:dark:bg-zinc-900',
|
||||
]}
|
||||
onclick={href ? undefined : onselect}
|
||||
{disabled}
|
||||
{href}
|
||||
{...rest}
|
||||
>
|
||||
{@render children?.()}
|
||||
</svelte:element>
|
||||
@@ -1,12 +1,14 @@
|
||||
<script lang="ts">
|
||||
import { Icon, type IconSource } from 'svelte-hero-icons'
|
||||
import type { ClassValue } from 'svelte/elements'
|
||||
|
||||
interface Props {
|
||||
icon?: IconSource | undefined
|
||||
title: string
|
||||
description?: string | undefined
|
||||
class?: string
|
||||
class?: ClassValue
|
||||
children?: import('svelte').Snippet
|
||||
iconClass?: ClassValue
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -15,6 +17,7 @@
|
||||
description = undefined,
|
||||
class: clazz = '',
|
||||
children,
|
||||
iconClass,
|
||||
}: Props = $props()
|
||||
</script>
|
||||
|
||||
@@ -24,7 +27,12 @@
|
||||
<div class="flex flex-col gap-2 items-center max-w-sm">
|
||||
{#if icon}
|
||||
<div
|
||||
class="bg-slate-100 dark:bg-zinc-900 p-3 rounded-2xl text-primary-900 dark:text-primary-100"
|
||||
class={[
|
||||
,
|
||||
iconClass
|
||||
? iconClass
|
||||
: 'bg-slate-100 dark:bg-zinc-900 p-3 rounded-2xl text-primary-900 dark:text-primary-100',
|
||||
]}
|
||||
>
|
||||
<Icon src={icon} size="28" solid />
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { invalidateAll } from '$app/navigation'
|
||||
import { page } from '$app/state'
|
||||
import TabButton from '$lib/components/input/switch/TabButton.svelte'
|
||||
import { SvelteURL } from 'svelte/reactivity'
|
||||
|
||||
interface Props {
|
||||
@@ -11,6 +12,7 @@
|
||||
currentRoute?: SvelteURL | undefined
|
||||
buildUrl?: (currentRoute: SvelteURL | undefined, href: string) => string
|
||||
children?: import('svelte').Snippet
|
||||
style?: 'header' | 'subpage'
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -18,6 +20,7 @@
|
||||
currentRoute = undefined,
|
||||
buildUrl = (_, href) => href,
|
||||
children,
|
||||
style = 'header',
|
||||
}: Props = $props()
|
||||
|
||||
function isSelected(url: URL, href?: SvelteURL) {
|
||||
@@ -27,25 +30,34 @@
|
||||
</script>
|
||||
|
||||
<nav
|
||||
class="flex flex-row items-center gap-x-8 gap-y-4 p-1 justify-center sm:justify-start my-2 sm:mt-0 flex-wrap z-20"
|
||||
class={[
|
||||
'flex flex-row items-center justify-center sm:justify-start my-2 sm:mt-0 flex-wrap z-20',
|
||||
style == 'header' ? 'p-1 gap-x-8 gap-y-4' : 'gap-3',
|
||||
]}
|
||||
>
|
||||
{#each routes as route (route.href)}
|
||||
{@const selected = isSelected(
|
||||
page.url,
|
||||
new SvelteURL(`${page.url.origin}${route.href}`),
|
||||
)}
|
||||
<a
|
||||
onclick={() => invalidateAll()}
|
||||
href={buildUrl(currentRoute, route.href)}
|
||||
class={[
|
||||
'rounded-full font-medium transition-colors duration-100 relative z-0 shrink-0 hover:text-slate-900 hover:dark:text-zinc-100',
|
||||
selected
|
||||
? 'text-primary-900 dark:text-primary-100'
|
||||
: 'text-slate-500 dark:text-zinc-500',
|
||||
]}
|
||||
>
|
||||
{route.name}
|
||||
</a>
|
||||
{#if style == 'header'}
|
||||
<a
|
||||
onclick={() => invalidateAll()}
|
||||
href={buildUrl(currentRoute, route.href)}
|
||||
class={[
|
||||
'rounded-full font-medium transition-colors duration-100 relative z-0 shrink-0 hover:text-slate-900 hover:dark:text-zinc-100',
|
||||
selected
|
||||
? 'text-primary-900 dark:text-primary-100'
|
||||
: 'text-slate-500 dark:text-zinc-500',
|
||||
]}
|
||||
>
|
||||
{route.name}
|
||||
</a>
|
||||
{:else}
|
||||
<TabButton href={buildUrl(currentRoute, route.href)} {selected}>
|
||||
{route.name}
|
||||
</TabButton>
|
||||
{/if}
|
||||
{/each}
|
||||
{@render children?.()}
|
||||
</nav>
|
||||
@@ -162,7 +162,8 @@
|
||||
"2fa": {
|
||||
"totp": "TOTP",
|
||||
"2fa": "2FA",
|
||||
"paste": "Paste this in your authenticator app."
|
||||
"paste": "Paste this in your authenticator app.",
|
||||
"disabled": "2FA is disabled"
|
||||
},
|
||||
"deleteAccount": {
|
||||
"label": "Delete account",
|
||||
@@ -172,6 +173,10 @@
|
||||
"languages": {
|
||||
"title": "Languages",
|
||||
"description": "If any are set, you will only see content explicitly tagged as that language. Most content, untagged, falls under 'Undetermined'."
|
||||
},
|
||||
"credentials": {
|
||||
"title": "Manage how you log in",
|
||||
"description": "You can enable 2FA for greater security, change your password, view logged in devices, or delete your account here."
|
||||
}
|
||||
},
|
||||
"email": "Email",
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { page } from '$app/state'
|
||||
import Header from '$lib/components/ui/layout/pages/Header.svelte'
|
||||
import SidebarButton from '$lib/components/ui/sidebar/SidebarButton.svelte'
|
||||
import Tabs from '$lib/components/ui/layout/pages/Tabs.svelte'
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {import('svelte').Snippet} [children]
|
||||
@@ -13,46 +13,36 @@
|
||||
let { children } = $props()
|
||||
|
||||
const routes = [
|
||||
{
|
||||
name: $t('routes.profile.credentials'),
|
||||
url: '/profile/password',
|
||||
},
|
||||
{
|
||||
name: $t('form.profile.2fa.2fa'),
|
||||
url: '/profile/password/2fa',
|
||||
href: '/profile/password/2fa',
|
||||
},
|
||||
{
|
||||
name: $t('routes.passwordChange.title'),
|
||||
url: '/profile/password/change',
|
||||
href: '/profile/password/change',
|
||||
},
|
||||
{
|
||||
name: $t('routes.profile.logins'),
|
||||
url: '/profile/password/logins',
|
||||
href: '/profile/password/logins',
|
||||
},
|
||||
{
|
||||
name: $t('routes.profile.delete.title'),
|
||||
url: '/profile/password/delete',
|
||||
href: '/profile/password/delete',
|
||||
},
|
||||
]
|
||||
</script>
|
||||
|
||||
<Header pageHeader>
|
||||
{routes.find(r => page.url.pathname == r.url)?.name}
|
||||
{routes.find(r => page.url.pathname == r.href)?.name ??
|
||||
$t('routes.profile.credentials')}
|
||||
</Header>
|
||||
<div class="flex flex-row gap-12">
|
||||
<nav class="flex flex-col gap-2 flex-1 max-sm:hidden">
|
||||
{#each routes as route (route)}
|
||||
<SidebarButton
|
||||
size="lg"
|
||||
rounding="lg"
|
||||
selected={page.url.pathname == route.url}
|
||||
href={route.url}
|
||||
>
|
||||
{route.name}
|
||||
</SidebarButton>
|
||||
{/each}
|
||||
</nav>
|
||||
<div class="flex-3 max-w-full w-full min-w-0">
|
||||
{@render children?.()}
|
||||
</div>
|
||||
|
||||
<Tabs style="subpage" {routes}></Tabs>
|
||||
<div
|
||||
class={[
|
||||
page.url.pathname == '/profile/password' && ' p-8',
|
||||
'flex flex-col justify-center items-center h-full',
|
||||
]}
|
||||
>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
@@ -1,103 +1,13 @@
|
||||
<script lang="ts">
|
||||
import EntityHeader from '$lib/components/ui/EntityHeader.svelte'
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
import { t } from '$lib/i18n/translations.js'
|
||||
import { Material } from 'mono-svelte'
|
||||
import {
|
||||
Icon,
|
||||
Identification,
|
||||
Key,
|
||||
Trash,
|
||||
UserGroup,
|
||||
} from 'svelte-hero-icons'
|
||||
|
||||
let { data } = $props()
|
||||
import { Key } from 'svelte-hero-icons'
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="grid grid-cols-1 lg:grid-cols-2 gap-4
|
||||
grid-rows-2"
|
||||
>
|
||||
<EntityHeader
|
||||
color="default"
|
||||
avatar={data.my_user?.local_user_view.person.avatar}
|
||||
name={$t('routes.profile.welcome', {
|
||||
default: data.my_user?.local_user_view.person.name,
|
||||
})}
|
||||
stats={[
|
||||
{
|
||||
name: $t('profile.subscribed'),
|
||||
value: data.my_user?.follows.length.toString() ?? '',
|
||||
},
|
||||
{
|
||||
name: $t('routes.profile.moderates'),
|
||||
value: data.my_user?.moderates.length.toString() ?? '',
|
||||
},
|
||||
]}
|
||||
rounding="2xl"
|
||||
class="row-span-2"
|
||||
<div class="h-full grid place-items-center">
|
||||
<Placeholder
|
||||
icon={Key}
|
||||
title={$t('form.profile.credentials.title')}
|
||||
description={$t('form.profile.credentials.description')}
|
||||
/>
|
||||
<a href="/profile/password/2fa" class="row-span-1">
|
||||
<Material
|
||||
class="hover:ring-primary-900 dark:hover:ring-primary-100 hover:ring-2 transition-all
|
||||
flex flex-col gap-2 h-full"
|
||||
rounding="2xl"
|
||||
>
|
||||
<Material
|
||||
rounding="full"
|
||||
padding="sm"
|
||||
color="default"
|
||||
class="h-max w-max"
|
||||
>
|
||||
<Icon src={Key} size="24" />
|
||||
</Material>
|
||||
<span class="font-medium text-lg">{$t('form.profile.2fa.2fa')}</span>
|
||||
<span class="text-sm">
|
||||
{data.my_user?.local_user_view.local_user.totp_2fa_enabled
|
||||
? $t('common.enabled')
|
||||
: $t('common.disabled')}
|
||||
</span>
|
||||
</Material>
|
||||
</a>
|
||||
<a href="/profile/password/change" class="row-span-1">
|
||||
<Material
|
||||
class="hover:ring-primary-900 dark:hover:ring-primary-100 hover:ring-2 transition-all
|
||||
flex flex-col gap-2 h-full"
|
||||
rounding="2xl"
|
||||
>
|
||||
<Material rounding="full" padding="sm" color="default" class="w-max">
|
||||
<Icon src={Identification} size="24" />
|
||||
</Material>
|
||||
<span class="font-medium text-lg">
|
||||
{$t('routes.passwordChange.title')}
|
||||
</span>
|
||||
</Material>
|
||||
</a>
|
||||
<a href="/profile/password/logins" class="sm:col-span-1">
|
||||
<Material
|
||||
class="hover:ring-primary-900 dark:hover:ring-primary-100 hover:ring-2 transition-all
|
||||
flex flex-col gap-2 h-full"
|
||||
rounding="2xl"
|
||||
>
|
||||
<Material rounding="full" padding="sm" color="default" class="w-max">
|
||||
<Icon src={UserGroup} size="24" />
|
||||
</Material>
|
||||
<span class="font-medium text-lg">
|
||||
{$t('routes.profile.logins')}
|
||||
</span>
|
||||
</Material>
|
||||
</a>
|
||||
<a href="/profile/password/delete" class="sm:col-span-1">
|
||||
<Material
|
||||
class="hover:ring-red-500 dark:hover:ring-red-500 hover:ring-2 transition-all
|
||||
flex flex-col gap-2 h-full text-red-500"
|
||||
rounding="2xl"
|
||||
>
|
||||
<Material rounding="full" padding="sm" color="default" class="w-max">
|
||||
<Icon src={Trash} size="24" />
|
||||
</Material>
|
||||
<span class="font-medium text-lg">
|
||||
{$t('routes.profile.delete.title')}
|
||||
</span>
|
||||
</Material>
|
||||
</a>
|
||||
</div>
|
||||
@@ -4,9 +4,10 @@
|
||||
import { client } from '$lib/lemmy.svelte.js'
|
||||
import { t } from '$lib/i18n/translations.js'
|
||||
import { qr } from '@svelte-put/qr/svg'
|
||||
import { Button, Material, TextInput, toast } from 'mono-svelte'
|
||||
import { ClipboardDocument, Icon } from 'svelte-hero-icons'
|
||||
import { Button, Material, Modal, TextInput, toast } from 'mono-svelte'
|
||||
import { ClipboardDocument, Icon, Key } from 'svelte-hero-icons'
|
||||
import { errorMessage } from '$lib/lemmy/error.js'
|
||||
import Placeholder from '$lib/components/ui/Placeholder.svelte'
|
||||
|
||||
let { data } = $props()
|
||||
|
||||
@@ -17,8 +18,18 @@
|
||||
|
||||
let verify_totp = $state('')
|
||||
|
||||
let openModal = $state(false)
|
||||
$effect(() => {
|
||||
if (!openModal) totpLink = undefined
|
||||
})
|
||||
|
||||
async function twofa(enabled: boolean, update: boolean = false) {
|
||||
try {
|
||||
if (!enabled && !update) {
|
||||
openModal = true
|
||||
return
|
||||
}
|
||||
|
||||
if (update) {
|
||||
await client().updateTotp({
|
||||
enabled: enabled,
|
||||
@@ -34,24 +45,23 @@
|
||||
} else {
|
||||
const res = await client().generateTotpSecret()
|
||||
totpLink = res.totp_secret_url
|
||||
totpEnabled = true
|
||||
openModal = true
|
||||
}
|
||||
} catch (e) {
|
||||
toast({ content: errorMessage(e as string), type: 'error' })
|
||||
} catch (err) {
|
||||
toast({ content: errorMessage(err as string), type: 'error' })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="w-full flex flex-col">
|
||||
<p class="">
|
||||
<span class="font-medium text-lg">
|
||||
{totpEnabled ? $t('common.enabled') : $t('common.disabled')}
|
||||
</span>
|
||||
</p>
|
||||
{#if totpEnabled || totpLink}
|
||||
<div class="w-full flex flex-col h-full">
|
||||
<Modal
|
||||
dismissable={false}
|
||||
bind:open={openModal}
|
||||
title={$t('form.profile.2fa.2fa')}
|
||||
>
|
||||
{#if totpLink && !totpEnabled}
|
||||
<Material color="transparent" class="fill-white!">
|
||||
<svg use:qr={{ data: totpLink, logo: '/img/logo-isolated.svg' }} />
|
||||
<Material rounding="2xl" color="uniform" class="">
|
||||
<svg use:qr={{ data: totpLink, logo: '/img/logo-background.svg' }} />
|
||||
</Material>
|
||||
<TextInput
|
||||
disabled
|
||||
@@ -76,25 +86,60 @@
|
||||
</span>
|
||||
</TextInput>
|
||||
{/if}
|
||||
<form class="flex flex-col gap-2 w-full" onsubmit={e => e.preventDefault()}>
|
||||
<form
|
||||
class="flex flex-col gap-2 w-full"
|
||||
onsubmit={e => {
|
||||
e.preventDefault()
|
||||
twofa(!(totpEnabled == true), true)
|
||||
}}
|
||||
>
|
||||
<TextInput
|
||||
bind:value={verify_totp}
|
||||
placeholder="012345"
|
||||
label={$t('form.2fa')}
|
||||
pattern={'\\d{6}'}
|
||||
required
|
||||
/>
|
||||
{#if totpEnabled}
|
||||
<Button onclick={() => twofa(false, true)} size="lg" color="primary">
|
||||
<Button submit size="lg" color="primary">
|
||||
{$t('common.disable')}
|
||||
</Button>
|
||||
{:else}
|
||||
<Button onclick={() => twofa(true, true)} size="lg" color="primary">
|
||||
<Button submit size="lg" color="primary">
|
||||
{$t('common.enable')}
|
||||
</Button>
|
||||
{/if}
|
||||
</form>
|
||||
{:else}
|
||||
<Button onclick={() => twofa(true)} size="lg" color="primary">
|
||||
{$t('form.setup')}
|
||||
</Button>
|
||||
{/if}
|
||||
</Modal>
|
||||
<div class="flex flex-col items-center justify-center h-full gap-4 p-4">
|
||||
{#if totpEnabled}
|
||||
<Placeholder
|
||||
iconClass="p-3 bg-green-100 text-green-600 dark:bg-green-500/10 dark:text-green-400 rounded-full"
|
||||
icon={Key}
|
||||
title={$t('form.profile.2fa.enabled')}
|
||||
>
|
||||
<Button
|
||||
onclick={() => twofa(false, false)}
|
||||
rounding="pill"
|
||||
color="primary"
|
||||
>
|
||||
{$t('common.disable')}
|
||||
</Button>
|
||||
</Placeholder>
|
||||
{:else}
|
||||
<Placeholder
|
||||
iconClass="p-3 bg-red-100 text-red-600 dark:bg-red-500/10 dark:text-red-400 rounded-full"
|
||||
icon={Key}
|
||||
title={$t('form.profile.2fa.disabled')}
|
||||
>
|
||||
<Button
|
||||
onclick={() => twofa(true, false)}
|
||||
rounding="pill"
|
||||
color="primary"
|
||||
>
|
||||
{$t('form.setup')}
|
||||
</Button>
|
||||
</Placeholder>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,11 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { preventDefault } from 'svelte/legacy'
|
||||
|
||||
import { client } from '$lib/lemmy.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { Button, TextInput, toast } from 'mono-svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { profile } from '$lib/auth.svelte'
|
||||
import { t } from '$lib/i18n/translations'
|
||||
import { client } from '$lib/lemmy.svelte'
|
||||
import { errorMessage } from '$lib/lemmy/error'
|
||||
import { Button, TextInput, toast } from 'mono-svelte'
|
||||
|
||||
let oldPassword = $state(''),
|
||||
newPassword = $state(''),
|
||||
@@ -42,7 +40,13 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<form onsubmit={preventDefault(changePassword)} class="flex flex-col gap-4">
|
||||
<form
|
||||
onsubmit={e => {
|
||||
e.preventDefault()
|
||||
changePassword()
|
||||
}}
|
||||
class="flex flex-col gap-4 w-full max-w-xl"
|
||||
>
|
||||
<TextInput
|
||||
bind:value={oldPassword}
|
||||
label={$t('form.profile.currentPassword')}
|
||||
@@ -64,14 +68,7 @@
|
||||
minlength={10}
|
||||
required
|
||||
/>
|
||||
<Button
|
||||
class="sm:ml-auto"
|
||||
size="lg"
|
||||
color="primary"
|
||||
submit
|
||||
{loading}
|
||||
disabled={loading}
|
||||
>
|
||||
<Button size="lg" color="primary" submit {loading} disabled={loading}>
|
||||
{$t('form.submit')}
|
||||
</Button>
|
||||
</form>
|
||||
Reference in new issue
Block a user