2026-07-31 18:26:08 +02:00
|
|
|
<script>
|
2026-08-04 17:05:37 +02:00
|
|
|
import { page } from '$app/state';
|
2026-09-05 12:08:12 +02:00
|
|
|
import { AppShell as SharedAppShell, ProfileDialog } from '@gabriel20xx/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 = [
|
2026-08-20 14:04:12 +02:00
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
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}
|
2026-08-05 14:58:07 +02:00
|
|
|
<AuthPage setupRequired={auth.status?.setupRequired ?? true} loading />
|
2026-08-01 12:51:02 +02:00
|
|
|
{:else if auth.error}
|
2026-08-05 14:58:07 +02:00
|
|
|
<AuthPage
|
|
|
|
|
setupRequired={auth.status?.setupRequired ?? true}
|
|
|
|
|
error={auth.error instanceof Error ? auth.error.message : 'Request failed.'}
|
|
|
|
|
/>
|
2026-08-01 12:51:02 +02:00
|
|
|
{: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
|
2026-08-19 16:58:43 +02:00
|
|
|
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)}
|
|
|
|
|
>
|
2026-08-05 14:58:07 +02:00
|
|
|
{@render children?.()}
|
2026-08-04 17:05:37 +02:00
|
|
|
</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
|
|
|
|
2026-08-20 14:04:12 +02:00
|
|
|
<SettingsDialog bind:open={settingsOpen} />
|
2026-08-04 17:05:37 +02:00
|
|
|
<ProfileDialog
|
|
|
|
|
bind:open={credentialsOpen}
|
|
|
|
|
currentUsername={auth.status?.username ?? ''}
|
|
|
|
|
currentEmail={auth.status?.email ?? ''}
|
|
|
|
|
onSave={saveProfile}
|
2026-08-05 14:58:07 +02:00
|
|
|
onTotpStatus={() => auth.totpStatus()}
|
|
|
|
|
onTotpSetup={() => auth.setupTotp()}
|
|
|
|
|
onTotpEnable={(token) => auth.enableTotp(token)}
|
|
|
|
|
onTotpDisable={(token) => auth.disableTotp(token)}
|
2026-08-04 17:05:37 +02:00
|
|
|
/>
|
2026-08-19 16:58:43 +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>
|