design: use better credentials tabs layout

This commit is contained in:
James Xylight committed 2025-08-24 10:56:37 -07:00
1 parent 952120a886
commit e5896505d2
9 files changed
+185 -189

No files matched your search

@@ -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>