2026-07-31 18:26:08 +02:00
|
|
|
<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';
|
2026-07-31 18:26:08 +02:00
|
|
|
import { Tooltip } from 'bits-ui';
|
2026-08-01 12:51:02 +02:00
|
|
|
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';
|
2026-07-31 18:26:08 +02:00
|
|
|
|
|
|
|
|
let { children } = $props();
|
2026-08-01 12:51:02 +02:00
|
|
|
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,
|
|
|
|
|
});
|
|
|
|
|
}
|
2026-07-31 18:26:08 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<Tooltip.Provider delayDuration={300}>
|
2026-08-01 12:51:02 +02:00
|
|
|
{#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()}
|
2026-08-01 12:51:02 +02:00
|
|
|
{@render children?.()}
|
2026-08-04 17:05:37 +02:00
|
|
|
{/snippet}
|
|
|
|
|
</SharedAppShell>
|
2026-08-01 12:51:02 +02:00
|
|
|
{/if}
|
2026-07-31 18:26:08 +02:00
|
|
|
</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}
|
|
|
|
|
/>
|