Files
CollabTable/frontend/src/lib/features/layout/AppShell.svelte
T

88 lines
3.3 KiB
Svelte
Raw Normal View History

<script>
2026-08-04 17:05:37 +02:00
import { page } from '$app/state';
import { AppShell as SharedAppShell, ProfileDialog } from '@gabriel20xx/web-ui';
import { Tooltip } from 'bits-ui';
import AuthPage from '$lib/features/auth/AuthPage.svelte';
import { createAuthStore } from '$lib/features/auth/auth.svelte.js';
2026-08-04 17:05:37 +02:00
import SettingsDialog from './SettingsDialog.svelte';
let { children } = $props();
const auth = createAuthStore();
2026-08-04 17:05:37 +02:00
const navItems = [
{
href: '/',
label: 'Overview',
icon: 'layout-dashboard',
description: 'Browse shared tables and collaborate on structured data.',
},
2026-08-04 17:05:37 +02:00
];
let settingsOpen = $state(false);
let credentialsOpen = $state(false);
async function saveProfile(input) {
// The backend's UpdateMe (POST /api/auth/credentials) requires a valid,
// non-empty email on every call - it has no concept of "leave this field
// unchanged" for email - so both username and email are always sent
// as-is; ProfileDialog's form always pre-fills and requires both fields,
// so they're never empty here. Only password is genuinely optional
// (blank means unchanged).
2026-08-04 17:05:37 +02:00
await auth.updateCredentials({
newUsername: input.username.trim(),
newEmail: input.email.trim(),
2026-08-04 17:05:37 +02:00
newPassword: input.password || undefined,
});
}
</script>
<Tooltip.Provider delayDuration={300}>
{#if auth.loading}
<AuthPage setupRequired={auth.status?.setupRequired ?? true} loading />
{:else if auth.error}
<AuthPage
setupRequired={auth.status?.setupRequired ?? true}
error={auth.error instanceof Error ? auth.error.message : 'Request failed.'}
/>
{:else if !auth.status || auth.status.setupRequired || !auth.status.authenticated}
<AuthPage setupRequired={auth.status?.setupRequired ?? true} />
{:else}
2026-08-04 17:05:37 +02:00
<SharedAppShell
class="collabtable-shell"
2026-08-04 17:05:37 +02:00
brand="CollabTable"
currentPath={page.url.pathname}
{navItems}
theme="system"
username={auth.status.username ?? ''}
onLogout={() => auth.logout()}
onProfile={() => (credentialsOpen = true)}
onSettings={() => (settingsOpen = true)}
>
{@render children?.()}
2026-08-04 17:05:37 +02:00
</SharedAppShell>
{/if}
</Tooltip.Provider>
2026-08-04 17:05:37 +02:00
<SettingsDialog bind:open={settingsOpen} />
2026-08-04 17:05:37 +02:00
<ProfileDialog
bind:open={credentialsOpen}
currentUsername={auth.status?.username ?? ''}
currentEmail={auth.status?.email ?? ''}
onSave={saveProfile}
onTotpStatus={() => auth.totpStatus()}
onTotpSetup={() => auth.setupTotp()}
onTotpEnable={(token) => auth.enableTotp(token)}
onTotpDisable={(token) => auth.disableTotp(token)}
2026-08-04 17:05:37 +02:00
/>
<style>
/* Most --sc-* bridging (primary/accent/ring, and the shared background/surface/border/status
tokens) now lives globally in app.css so it also reaches shared components rendered outside
this scope (AuthPage, the Settings/Profile dialogs). --sc-secondary is a subtle tinted-surface
color for low-emphasis buttons here, a different role than this app's own saturated
--color-secondary, so it stays local rather than overriding --color-secondary's shared
meaning workspace-wide. */
:global(.collabtable-shell) {
--sc-secondary: color-mix(in srgb, var(--color-primary) 12%, var(--color-surface));
--sc-secondary-hover: color-mix(in srgb, var(--color-primary) 20%, var(--color-surface));
--sc-secondary-fg: var(--color-fg);
}
</style>