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

77 lines
2.6 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}
<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
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
/>