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

115 lines
4.3 KiB
Svelte
Raw Normal View History

<script>
2026-08-04 17:05:37 +02:00
import { page } from '$app/state';
import { AdminDialog, 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);
let adminOpen = $state(false);
const isAdmin = $derived(auth.status?.role === 'admin' || auth.status?.role === 'superadmin');
2026-08-04 17:05:37 +02:00
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)}
onAdmin={isAdmin ? () => (adminOpen = true) : undefined}
2026-08-04 17:05:37 +02:00
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} />
<AdminDialog
bind:open={adminOpen}
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 ?? ''}
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>
/* 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>