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

+7 -13
View File
@@ -1,4 +1,6 @@
<script lang="ts"> <script lang="ts">
import TabButton from './switch/TabButton.svelte'
type T = $$Generic type T = $$Generic
interface Props { interface Props {
@@ -29,22 +31,14 @@
> >
{#each options as option, index} {#each options as option, index}
{@const slctd = selected == option} {@const slctd = selected == option}
<button <TabButton
class={[ selected={slctd}
'px-2.5 py-1 rounded-xl text-sm font-medium transition-colors duration-75 relative cursor-pointer', onselect={() => (selected = option)}
slctd disabled={disabled[index]}
? '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}
type="button" type="button"
> >
{optionNames[index] || option} {optionNames[index] || option}
</button> </TabButton>
{/each} {/each}
</div> </div>
{@render children?.({ selected })} {@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>
+10 -2
View File
@@ -1,12 +1,14 @@
<script lang="ts"> <script lang="ts">
import { Icon, type IconSource } from 'svelte-hero-icons' import { Icon, type IconSource } from 'svelte-hero-icons'
import type { ClassValue } from 'svelte/elements'
interface Props { interface Props {
icon?: IconSource | undefined icon?: IconSource | undefined
title: string title: string
description?: string | undefined description?: string | undefined
class?: string class?: ClassValue
children?: import('svelte').Snippet children?: import('svelte').Snippet
iconClass?: ClassValue
} }
let { let {
@@ -15,6 +17,7 @@
description = undefined, description = undefined,
class: clazz = '', class: clazz = '',
children, children,
iconClass,
}: Props = $props() }: Props = $props()
</script> </script>
@@ -24,7 +27,12 @@
<div class="flex flex-col gap-2 items-center max-w-sm"> <div class="flex flex-col gap-2 items-center max-w-sm">
{#if icon} {#if icon}
<div <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 /> <Icon src={icon} size="28" solid />
</div> </div>
+25 -13
View File
@@ -1,6 +1,7 @@
<script lang="ts"> <script lang="ts">
import { invalidateAll } from '$app/navigation' import { invalidateAll } from '$app/navigation'
import { page } from '$app/state' import { page } from '$app/state'
import TabButton from '$lib/components/input/switch/TabButton.svelte'
import { SvelteURL } from 'svelte/reactivity' import { SvelteURL } from 'svelte/reactivity'
interface Props { interface Props {
@@ -11,6 +12,7 @@
currentRoute?: SvelteURL | undefined currentRoute?: SvelteURL | undefined
buildUrl?: (currentRoute: SvelteURL | undefined, href: string) => string buildUrl?: (currentRoute: SvelteURL | undefined, href: string) => string
children?: import('svelte').Snippet children?: import('svelte').Snippet
style?: 'header' | 'subpage'
} }
let { let {
@@ -18,6 +20,7 @@
currentRoute = undefined, currentRoute = undefined,
buildUrl = (_, href) => href, buildUrl = (_, href) => href,
children, children,
style = 'header',
}: Props = $props() }: Props = $props()
function isSelected(url: URL, href?: SvelteURL) { function isSelected(url: URL, href?: SvelteURL) {
@@ -27,25 +30,34 @@
</script> </script>
<nav <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)} {#each routes as route (route.href)}
{@const selected = isSelected( {@const selected = isSelected(
page.url, page.url,
new SvelteURL(`${page.url.origin}${route.href}`), new SvelteURL(`${page.url.origin}${route.href}`),
)} )}
<a {#if style == 'header'}
onclick={() => invalidateAll()} <a
href={buildUrl(currentRoute, route.href)} onclick={() => invalidateAll()}
class={[ href={buildUrl(currentRoute, route.href)}
'rounded-full font-medium transition-colors duration-100 relative z-0 shrink-0 hover:text-slate-900 hover:dark:text-zinc-100', class={[
selected 'rounded-full font-medium transition-colors duration-100 relative z-0 shrink-0 hover:text-slate-900 hover:dark:text-zinc-100',
? 'text-primary-900 dark:text-primary-100' selected
: 'text-slate-500 dark:text-zinc-500', ? 'text-primary-900 dark:text-primary-100'
]} : 'text-slate-500 dark:text-zinc-500',
> ]}
{route.name} >
</a> {route.name}
</a>
{:else}
<TabButton href={buildUrl(currentRoute, route.href)} {selected}>
{route.name}
</TabButton>
{/if}
{/each} {/each}
{@render children?.()} {@render children?.()}
</nav> </nav>
+6 -1
View File
@@ -162,7 +162,8 @@
"2fa": { "2fa": {
"totp": "TOTP", "totp": "TOTP",
"2fa": "2FA", "2fa": "2FA",
"paste": "Paste this in your authenticator app." "paste": "Paste this in your authenticator app.",
"disabled": "2FA is disabled"
}, },
"deleteAccount": { "deleteAccount": {
"label": "Delete account", "label": "Delete account",
@@ -172,6 +173,10 @@
"languages": { "languages": {
"title": "Languages", "title": "Languages",
"description": "If any are set, you will only see content explicitly tagged as that language. Most content, untagged, falls under 'Undetermined'." "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", "email": "Email",
@@ -3,7 +3,7 @@
import { page } from '$app/state' import { page } from '$app/state'
import Header from '$lib/components/ui/layout/pages/Header.svelte' 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 * @typedef {Object} Props
* @property {import('svelte').Snippet} [children] * @property {import('svelte').Snippet} [children]
@@ -13,46 +13,36 @@
let { children } = $props() let { children } = $props()
const routes = [ const routes = [
{
name: $t('routes.profile.credentials'),
url: '/profile/password',
},
{ {
name: $t('form.profile.2fa.2fa'), name: $t('form.profile.2fa.2fa'),
url: '/profile/password/2fa', href: '/profile/password/2fa',
}, },
{ {
name: $t('routes.passwordChange.title'), name: $t('routes.passwordChange.title'),
url: '/profile/password/change', href: '/profile/password/change',
}, },
{ {
name: $t('routes.profile.logins'), name: $t('routes.profile.logins'),
url: '/profile/password/logins', href: '/profile/password/logins',
}, },
{ {
name: $t('routes.profile.delete.title'), name: $t('routes.profile.delete.title'),
url: '/profile/password/delete', href: '/profile/password/delete',
}, },
] ]
</script> </script>
<Header pageHeader> <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> </Header>
<div class="flex flex-row gap-12">
<nav class="flex flex-col gap-2 flex-1 max-sm:hidden"> <Tabs style="subpage" {routes}></Tabs>
{#each routes as route (route)} <div
<SidebarButton class={[
size="lg" page.url.pathname == '/profile/password' && ' p-8',
rounding="lg" 'flex flex-col justify-center items-center h-full',
selected={page.url.pathname == route.url} ]}
href={route.url} >
> {@render children?.()}
{route.name}
</SidebarButton>
{/each}
</nav>
<div class="flex-3 max-w-full w-full min-w-0">
{@render children?.()}
</div>
</div> </div>
@@ -1,103 +1,13 @@
<script lang="ts"> <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 { t } from '$lib/i18n/translations.js'
import { Material } from 'mono-svelte' import { Key } from 'svelte-hero-icons'
import {
Icon,
Identification,
Key,
Trash,
UserGroup,
} from 'svelte-hero-icons'
let { data } = $props()
</script> </script>
<div <div class="h-full grid place-items-center">
class="grid grid-cols-1 lg:grid-cols-2 gap-4 <Placeholder
grid-rows-2" icon={Key}
> title={$t('form.profile.credentials.title')}
<EntityHeader description={$t('form.profile.credentials.description')}
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"
/> />
<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> </div>
@@ -4,9 +4,10 @@
import { client } from '$lib/lemmy.svelte.js' import { client } from '$lib/lemmy.svelte.js'
import { t } from '$lib/i18n/translations.js' import { t } from '$lib/i18n/translations.js'
import { qr } from '@svelte-put/qr/svg' import { qr } from '@svelte-put/qr/svg'
import { Button, Material, TextInput, toast } from 'mono-svelte' import { Button, Material, Modal, TextInput, toast } from 'mono-svelte'
import { ClipboardDocument, Icon } from 'svelte-hero-icons' import { ClipboardDocument, Icon, Key } from 'svelte-hero-icons'
import { errorMessage } from '$lib/lemmy/error.js' import { errorMessage } from '$lib/lemmy/error.js'
import Placeholder from '$lib/components/ui/Placeholder.svelte'
let { data } = $props() let { data } = $props()
@@ -17,8 +18,18 @@
let verify_totp = $state('') let verify_totp = $state('')
let openModal = $state(false)
$effect(() => {
if (!openModal) totpLink = undefined
})
async function twofa(enabled: boolean, update: boolean = false) { async function twofa(enabled: boolean, update: boolean = false) {
try { try {
if (!enabled && !update) {
openModal = true
return
}
if (update) { if (update) {
await client().updateTotp({ await client().updateTotp({
enabled: enabled, enabled: enabled,
@@ -34,24 +45,23 @@
} else { } else {
const res = await client().generateTotpSecret() const res = await client().generateTotpSecret()
totpLink = res.totp_secret_url totpLink = res.totp_secret_url
totpEnabled = true openModal = true
} }
} catch (e) { } catch (err) {
toast({ content: errorMessage(e as string), type: 'error' }) toast({ content: errorMessage(err as string), type: 'error' })
} }
} }
</script> </script>
<div class="w-full flex flex-col"> <div class="w-full flex flex-col h-full">
<p class=""> <Modal
<span class="font-medium text-lg"> dismissable={false}
{totpEnabled ? $t('common.enabled') : $t('common.disabled')} bind:open={openModal}
</span> title={$t('form.profile.2fa.2fa')}
</p> >
{#if totpEnabled || totpLink}
{#if totpLink && !totpEnabled} {#if totpLink && !totpEnabled}
<Material color="transparent" class="fill-white!"> <Material rounding="2xl" color="uniform" class="">
<svg use:qr={{ data: totpLink, logo: '/img/logo-isolated.svg' }} /> <svg use:qr={{ data: totpLink, logo: '/img/logo-background.svg' }} />
</Material> </Material>
<TextInput <TextInput
disabled disabled
@@ -76,25 +86,60 @@
</span> </span>
</TextInput> </TextInput>
{/if} {/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 <TextInput
bind:value={verify_totp} bind:value={verify_totp}
placeholder="012345" placeholder="012345"
label={$t('form.2fa')} label={$t('form.2fa')}
pattern={'\\d{6}'}
required
/> />
{#if totpEnabled} {#if totpEnabled}
<Button onclick={() => twofa(false, true)} size="lg" color="primary"> <Button submit size="lg" color="primary">
{$t('common.disable')} {$t('common.disable')}
</Button> </Button>
{:else} {:else}
<Button onclick={() => twofa(true, true)} size="lg" color="primary"> <Button submit size="lg" color="primary">
{$t('common.enable')} {$t('common.enable')}
</Button> </Button>
{/if} {/if}
</form> </form>
{:else} </Modal>
<Button onclick={() => twofa(true)} size="lg" color="primary"> <div class="flex flex-col items-center justify-center h-full gap-4 p-4">
{$t('form.setup')} {#if totpEnabled}
</Button> <Placeholder
{/if} 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> </div>
@@ -1,11 +1,9 @@
<script lang="ts"> <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 { 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(''), let oldPassword = $state(''),
newPassword = $state(''), newPassword = $state(''),
@@ -42,7 +40,13 @@
} }
</script> </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 <TextInput
bind:value={oldPassword} bind:value={oldPassword}
label={$t('form.profile.currentPassword')} label={$t('form.profile.currentPassword')}
@@ -64,14 +68,7 @@
minlength={10} minlength={10}
required required
/> />
<Button <Button size="lg" color="primary" submit {loading} disabled={loading}>
class="sm:ml-auto"
size="lg"
color="primary"
submit
{loading}
disabled={loading}
>
{$t('form.submit')} {$t('form.submit')}
</Button> </Button>
</form> </form>