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

113 lines
4.5 KiB
Svelte
Raw Normal View History

<script>
2026-08-04 17:05:37 +02:00
import { page } from '$app/state';
2026-08-06 15:52:56 +02:00
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 = [
2026-08-07 15:22:26 +02:00
{ href: '/', label: 'Overview', icon: 'layout-dashboard', description: 'Browse shared tables and collaborate on structured data.' },
{ href: '/about', label: 'About', icon: 'info', description: 'Learn about CollabTable and its collaboration features.' },
2026-08-04 17:05:37 +02:00
];
let settingsOpen = $state(false);
let credentialsOpen = $state(false);
async function saveProfile(input) {
await auth.updateCredentials({
newUsername: input.username.trim() || undefined,
newEmail: input.email.trim() || undefined,
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}
currentRole={auth.status?.role ?? 'user'}
currentUserId={auth.status?.id}
onCreateUser={(input) => auth.createUser(input)}
onDeleteUser={(id) => auth.deleteUser(id)}
onListUsers={() => auth.listUsers()}
onUpdateUser={(id, input) => auth.updateUser(id, input)}
/>
2026-08-04 17:05:37 +02:00
<ProfileDialog
bind:open={credentialsOpen}
currentUsername={auth.status?.username ?? ''}
currentEmail={auth.status?.email ?? ''}
currentRole={auth.status?.role ?? 'user'}
currentUserId={auth.status?.id}
onCreateUser={(input) => auth.createUser(input)}
onDeleteUser={(id) => auth.deleteUser(id)}
onListUsers={() => auth.listUsers()}
2026-08-04 17:05:37 +02:00
onSave={saveProfile}
onUpdateUser={(id, input) => auth.updateUser(id, input)}
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>
/* The shared component library (header, page title box, dialogs, buttons, ...) otherwise
renders in its own generic default palette instead of this app's own branding - remap its
--sc-* tokens onto this app's own --color-* palette so every shared component follows suit.
--sc-secondary is a subtle tinted-surface color for low-emphasis buttons, a different role
than this app's own saturated --color-secondary, so it's derived instead of mapped directly. */
:global(.collabtable-shell) {
--sc-bg: var(--color-bg);
--sc-surface: var(--color-surface);
--sc-surface-raised: var(--color-surface);
--sc-surface-hover: var(--color-surface-hover);
--sc-border: var(--color-border);
--sc-border-strong: var(--color-border);
--sc-fg: var(--color-fg);
--sc-muted-fg: var(--color-muted-fg);
--sc-subtle-fg: var(--color-muted-fg);
--sc-primary: var(--color-primary);
--sc-primary-hover: var(--color-secondary);
--sc-primary-fg: var(--color-primary-fg);
--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);
--sc-accent: var(--color-accent);
--sc-accent-fg: var(--color-accent-fg);
--sc-danger: var(--color-danger);
--sc-danger-hover: color-mix(in srgb, var(--color-danger) 90%, black);
--sc-danger-fg: var(--color-danger-fg);
--sc-success: var(--color-success);
--sc-success-fg: var(--color-success-fg);
--sc-warning: var(--color-warning);
--sc-warning-fg: var(--color-warning-fg);
--sc-ring: var(--color-ring);
}
</style>