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

60 lines
2.0 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/shared-code/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' },
{ href: '/about', label: 'About' },
];
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}
<div class="flex min-h-screen items-center justify-center text-sm text-muted-fg">Loading…</div>
{:else if auth.error}
<div class="flex min-h-screen items-center justify-center px-4 text-sm text-danger">
{auth.error instanceof Error ? auth.error.message : 'Request failed.'}
</div>
{: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
brand="CollabTable"
currentPath={page.url.pathname}
{navItems}
theme="system"
username={auth.status.username ?? ''}
onLogout={() => auth.logout()}
onProfile={() => (credentialsOpen = true)}
onSettings={() => (settingsOpen = true)}
>
{#snippet children()}
{@render children?.()}
2026-08-04 17:05:37 +02:00
{/snippet}
</SharedAppShell>
{/if}
</Tooltip.Provider>
2026-08-04 17:05:37 +02:00
<SettingsDialog bind:open={settingsOpen} />
<ProfileDialog
bind:open={credentialsOpen}
currentUsername={auth.status?.username ?? ''}
currentEmail={auth.status?.email ?? ''}
onSave={saveProfile}
/>