Migrate shared UI and backend components
This commit is contained in:
1 parent
64d22d0aac
commit
ac08be0248
16 files changed
+236
-395
No files matched your search
@@ -1,126 +0,0 @@
|
||||
<script module>
|
||||
import { Info, LayoutDashboard } from '@lucide/svelte';
|
||||
|
||||
const navItems = [
|
||||
{ to: '/', end: true, icon: LayoutDashboard, label: 'Overview' },
|
||||
{ to: '/about', icon: Info, label: 'About' },
|
||||
];
|
||||
|
||||
function isActive(pathname, target, end) {
|
||||
if (end) return pathname === target;
|
||||
return pathname === target || pathname.startsWith(`${target}/`);
|
||||
}
|
||||
</script>
|
||||
|
||||
<script>
|
||||
import { page } from '$app/state';
|
||||
import { resolve } from '$app/paths';
|
||||
import { LogOut, Menu, Table2, Settings, UserRound, X } from '@lucide/svelte';
|
||||
import { cn } from '$lib/utils/cn.js';
|
||||
import Button from '$lib/components/ui/button.svelte';
|
||||
import HealthWidget from '$lib/features/health/HealthWidget.svelte';
|
||||
import SettingsDialog from '$lib/features/layout/SettingsDialog.svelte';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '$lib/components/ui/dropdown-menu';
|
||||
import { useAuth } from '$lib/features/auth/auth.svelte.js';
|
||||
import CredentialsDialog from '$lib/features/auth/CredentialsDialog.svelte';
|
||||
|
||||
const navLinkClass = (active) =>
|
||||
cn(
|
||||
'inline-flex shrink-0 items-center gap-2 whitespace-nowrap rounded-md px-3 py-1.5 text-sm font-medium transition-colors hover:bg-surface-hover',
|
||||
active && 'bg-surface-hover text-primary',
|
||||
);
|
||||
|
||||
const auth = useAuth();
|
||||
|
||||
let navOpen = $state(false);
|
||||
let settingsOpen = $state(false);
|
||||
let credentialsOpen = $state(false);
|
||||
</script>
|
||||
|
||||
<header class="sticky top-0 z-40 flex h-14 items-center gap-2 border-b border-border bg-bg px-3">
|
||||
<a href={resolve('/')} class="flex shrink-0 items-center gap-2 pr-1 font-semibold text-fg">
|
||||
<Table2 class="size-5 text-primary" />
|
||||
<span>CollabTable</span>
|
||||
</a>
|
||||
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
class="ml-auto min-[640px]:hidden"
|
||||
aria-label="Toggle navigation"
|
||||
aria-expanded={navOpen}
|
||||
aria-controls="primary-navigation"
|
||||
onclick={() => (navOpen = !navOpen)}
|
||||
>
|
||||
{#if navOpen}
|
||||
<X class="size-5" />
|
||||
{:else}
|
||||
<Menu class="size-5" />
|
||||
{/if}
|
||||
</Button>
|
||||
|
||||
<nav
|
||||
id="primary-navigation"
|
||||
class={cn(
|
||||
'min-[640px]:flex min-[640px]:items-center min-[640px]:gap-1',
|
||||
'absolute left-0 right-0 top-full flex flex-col gap-1 border-b border-border bg-bg p-2 shadow-lg min-[640px]:static min-[640px]:flex-row min-[640px]:border-b-0 min-[640px]:bg-transparent min-[640px]:p-0 min-[640px]:shadow-none',
|
||||
!navOpen && 'hidden min-[640px]:flex',
|
||||
)}
|
||||
>
|
||||
{#each navItems as item (item.to)}
|
||||
{@const href = resolve(item.to)}
|
||||
<a
|
||||
{href}
|
||||
class={cn(
|
||||
navLinkClass(isActive(page.url.pathname, href, item.end)),
|
||||
'w-full justify-start py-2 min-[640px]:w-auto min-[640px]:py-1.5',
|
||||
)}
|
||||
onclick={() => (navOpen = false)}
|
||||
>
|
||||
<item.icon class="size-4" />
|
||||
{item.label}
|
||||
</a>
|
||||
{/each}
|
||||
</nav>
|
||||
|
||||
<div class="flex shrink-0 items-center gap-1 min-[640px]:ml-auto">
|
||||
<HealthWidget />
|
||||
<Button variant="ghost" size="icon" aria-label="Settings" onclick={() => (settingsOpen = true)}>
|
||||
<Settings class="size-5" />
|
||||
</Button>
|
||||
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger>
|
||||
{#snippet child({ props })}
|
||||
<Button variant="ghost" size="sm" class="max-[639px]:size-9 max-[639px]:p-0" aria-label="Account" {...props}>
|
||||
<UserRound class="size-5" />
|
||||
<span class="hidden min-[640px]:inline">{auth.status?.username ?? ''}</span>
|
||||
</Button>
|
||||
{/snippet}
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuItem onSelect={() => (credentialsOpen = true)}>
|
||||
<UserRound class="size-4" />
|
||||
Profile
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem onSelect={() => void auth.logout()}>
|
||||
<LogOut class="size-4" />
|
||||
Sign out
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</header>
|
||||
<CredentialsDialog
|
||||
bind:open={credentialsOpen}
|
||||
currentUsername={auth.status?.username ?? ''}
|
||||
currentEmail={auth.status?.email ?? ''}
|
||||
/>
|
||||
<SettingsDialog bind:open={settingsOpen} />
|
||||
@@ -1,119 +1,18 @@
|
||||
<script>
|
||||
import { Table2 } from '@lucide/svelte';
|
||||
import Button from '$lib/components/ui/button.svelte';
|
||||
import { AuthPage as SharedAuthPage } from '@gabriel20xx/shared-code/web-ui';
|
||||
import { useAuth } from '$lib/features/auth/auth.svelte.js';
|
||||
|
||||
let { setupRequired } = $props();
|
||||
|
||||
const auth = useAuth();
|
||||
|
||||
let username = $state('');
|
||||
let email = $state('');
|
||||
let identifier = $state('');
|
||||
let password = $state('');
|
||||
let confirmPassword = $state('');
|
||||
let submitting = $state(false);
|
||||
let error = $state('');
|
||||
|
||||
async function submit(event) {
|
||||
event.preventDefault();
|
||||
error = '';
|
||||
|
||||
if (setupRequired && password !== confirmPassword) {
|
||||
error = 'Passwords do not match.';
|
||||
return;
|
||||
}
|
||||
|
||||
submitting = true;
|
||||
try {
|
||||
if (setupRequired) {
|
||||
await auth.setup(username, email, password);
|
||||
} else {
|
||||
await auth.login(identifier, password);
|
||||
}
|
||||
} catch (submitError) {
|
||||
error = submitError instanceof Error ? submitError.message : 'Request failed.';
|
||||
} finally {
|
||||
submitting = false;
|
||||
}
|
||||
}
|
||||
const onLogin = (input) => auth.login(input.identifier, input.password);
|
||||
const onSetup = (input) => auth.setup(input.username, input.email, input.password);
|
||||
</script>
|
||||
|
||||
<main class="flex min-h-screen items-center justify-center bg-bg px-4 py-8">
|
||||
<section class="w-full max-w-sm rounded-lg border border-border bg-surface p-6 shadow-sm">
|
||||
<div class="mb-6 flex flex-col items-center gap-2 text-center">
|
||||
<Table2 class="size-8 text-primary" />
|
||||
<h1 class="text-xl font-semibold">CollabTable</h1>
|
||||
<p class="text-sm text-muted-fg">
|
||||
{setupRequired ? 'Create the admin account for this dashboard.' : 'Sign in to view this dashboard.'}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<form class="space-y-4" onsubmit={submit}>
|
||||
{#if setupRequired}
|
||||
<label for="auth-username" class="mb-1 block text-sm font-medium">Username</label>
|
||||
<!-- svelte-ignore a11y_autofocus -->
|
||||
<input
|
||||
id="auth-username"
|
||||
class="h-9 w-full rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
bind:value={username}
|
||||
autocomplete="username"
|
||||
required
|
||||
autofocus
|
||||
/>
|
||||
<label for="auth-email" class="mb-1 block text-sm font-medium">Email</label>
|
||||
<input
|
||||
id="auth-email"
|
||||
type="email"
|
||||
class="h-9 w-full rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
bind:value={email}
|
||||
autocomplete="email"
|
||||
required
|
||||
/>
|
||||
{:else}
|
||||
<label for="auth-identifier" class="mb-1 block text-sm font-medium">Username or email</label>
|
||||
<!-- svelte-ignore a11y_autofocus -->
|
||||
<input
|
||||
id="auth-identifier"
|
||||
class="h-9 w-full rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
bind:value={identifier}
|
||||
autocomplete="username"
|
||||
required
|
||||
autofocus
|
||||
/>
|
||||
{/if}
|
||||
<div>
|
||||
<label for="auth-password" class="mb-1 block text-sm font-medium">Password</label>
|
||||
<input
|
||||
id="auth-password"
|
||||
type="password"
|
||||
class="h-9 w-full rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
bind:value={password}
|
||||
autocomplete={setupRequired ? 'new-password' : 'current-password'}
|
||||
minlength={8}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
{#if setupRequired}
|
||||
<div>
|
||||
<label for="auth-confirm-password" class="mb-1 block text-sm font-medium">Confirm password</label>
|
||||
<input
|
||||
id="auth-confirm-password"
|
||||
type="password"
|
||||
class="h-9 w-full rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
bind:value={confirmPassword}
|
||||
autocomplete="new-password"
|
||||
minlength={8}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
{#if error}
|
||||
<p class="text-sm text-danger">{error}</p>
|
||||
{/if}
|
||||
<Button type="submit" class="w-full" disabled={submitting}>
|
||||
{submitting ? 'Working…' : setupRequired ? 'Create account' : 'Sign in'}
|
||||
</Button>
|
||||
</form>
|
||||
</section>
|
||||
</main>
|
||||
<SharedAuthPage
|
||||
brand="CollabTable"
|
||||
tagline="Collaborative tables for your team"
|
||||
{setupRequired}
|
||||
{onLogin}
|
||||
{onSetup}
|
||||
/>
|
||||
@@ -1,111 +0,0 @@
|
||||
<script>
|
||||
import Button from '$lib/components/ui/button.svelte';
|
||||
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '$lib/components/ui/dialog';
|
||||
import { useAuth } from '$lib/features/auth/auth.svelte.js';
|
||||
|
||||
let { open = $bindable(false), currentUsername, currentEmail } = $props();
|
||||
|
||||
const auth = useAuth();
|
||||
|
||||
let username = $state('');
|
||||
let email = $state('');
|
||||
let newPassword = $state('');
|
||||
let confirmPassword = $state('');
|
||||
let error = $state('');
|
||||
let saving = $state(false);
|
||||
|
||||
$effect(() => {
|
||||
if (open) {
|
||||
username = currentUsername;
|
||||
email = currentEmail;
|
||||
}
|
||||
});
|
||||
|
||||
async function submit(event) {
|
||||
event.preventDefault();
|
||||
error = '';
|
||||
if (newPassword !== confirmPassword) {
|
||||
error = 'Passwords do not match.';
|
||||
return;
|
||||
}
|
||||
|
||||
saving = true;
|
||||
try {
|
||||
await auth.updateCredentials({
|
||||
newUsername: username.trim() || undefined,
|
||||
newEmail: email.trim() || undefined,
|
||||
newPassword: newPassword || undefined,
|
||||
});
|
||||
newPassword = '';
|
||||
confirmPassword = '';
|
||||
open = false;
|
||||
} catch (saveError) {
|
||||
error = saveError instanceof Error ? saveError.message : 'Request failed.';
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<Dialog bind:open>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Account</DialogTitle>
|
||||
</DialogHeader>
|
||||
<form class="space-y-4" onsubmit={submit}>
|
||||
<p class="text-sm text-muted-fg">Changing your credentials will sign you out everywhere.</p>
|
||||
<div>
|
||||
<label for="credentials-username" class="mb-1 block text-sm font-medium">Username</label>
|
||||
<input
|
||||
id="credentials-username"
|
||||
class="h-9 w-full rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
bind:value={username}
|
||||
autocomplete="username"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="credentials-email" class="mb-1 block text-sm font-medium">Email</label>
|
||||
<input
|
||||
id="credentials-email"
|
||||
type="email"
|
||||
class="h-9 w-full rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
bind:value={email}
|
||||
autocomplete="email"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="credentials-new-password" class="mb-1 block text-sm font-medium">New password</label>
|
||||
<input
|
||||
id="credentials-new-password"
|
||||
type="password"
|
||||
class="h-9 w-full rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
bind:value={newPassword}
|
||||
autocomplete="new-password"
|
||||
minlength={8}
|
||||
placeholder="Leave blank to keep your password"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="credentials-confirm-password" class="mb-1 block text-sm font-medium">Confirm new password</label>
|
||||
<input
|
||||
id="credentials-confirm-password"
|
||||
type="password"
|
||||
class="h-9 w-full rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||
bind:value={confirmPassword}
|
||||
autocomplete="new-password"
|
||||
minlength={8}
|
||||
/>
|
||||
</div>
|
||||
{#if error}
|
||||
<p class="text-sm text-danger">{error}</p>
|
||||
{/if}
|
||||
<DialogFooter>
|
||||
<Button type="submit" disabled={saving}>
|
||||
{saving ? 'Saving…' : 'Save'}
|
||||
</Button>
|
||||
<Button type="button" variant="secondary" onclick={() => (open = false)}>Dismiss</Button>
|
||||
</DialogFooter>
|
||||
</form>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
@@ -1,12 +1,27 @@
|
||||
<script>
|
||||
import { page } from '$app/state';
|
||||
import { AppShell as SharedAppShell, ProfileDialog } from '@gabriel20xx/shared-code/web-ui';
|
||||
import { Tooltip } from 'bits-ui';
|
||||
import Header from '$lib/components/Header.svelte';
|
||||
import AuthPage from '$lib/features/auth/AuthPage.svelte';
|
||||
import { createAuthStore } from '$lib/features/auth/auth.svelte.js';
|
||||
import SettingsDialog from './SettingsDialog.svelte';
|
||||
|
||||
let { children } = $props();
|
||||
|
||||
const auth = createAuthStore();
|
||||
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}>
|
||||
@@ -19,11 +34,27 @@
|
||||
{:else if !auth.status || auth.status.setupRequired || !auth.status.authenticated}
|
||||
<AuthPage setupRequired={auth.status?.setupRequired ?? true} />
|
||||
{:else}
|
||||
<div class="flex min-h-screen flex-col">
|
||||
<Header />
|
||||
<main class="flex min-w-0 flex-1 flex-col">
|
||||
<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?.()}
|
||||
</main>
|
||||
</div>
|
||||
{/snippet}
|
||||
</SharedAppShell>
|
||||
{/if}
|
||||
</Tooltip.Provider>
|
||||
|
||||
<SettingsDialog bind:open={settingsOpen} />
|
||||
<ProfileDialog
|
||||
bind:open={credentialsOpen}
|
||||
currentUsername={auth.status?.username ?? ''}
|
||||
currentEmail={auth.status?.email ?? ''}
|
||||
onSave={saveProfile}
|
||||
/>
|
||||
@@ -1,7 +1,7 @@
|
||||
<script>
|
||||
import { Moon, Sun, SunMoon } from '@lucide/svelte';
|
||||
import Button from '$lib/components/ui/button.svelte';
|
||||
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '$lib/components/ui/dialog';
|
||||
import { SettingsDialog as SharedSettingsDialog } from '@gabriel20xx/shared-code/web-ui';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '$lib/components/ui/select';
|
||||
import { currentLanguage, languages, setLanguage } from '$lib/language.svelte.js';
|
||||
import { themeState } from '$lib/theme.svelte.js';
|
||||
@@ -11,11 +11,7 @@
|
||||
const languageItems = languages.map((language) => ({ value: language.id, label: language.label }));
|
||||
</script>
|
||||
|
||||
<Dialog bind:open>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Settings</DialogTitle>
|
||||
</DialogHeader>
|
||||
<SharedSettingsDialog bind:open title="Settings">
|
||||
<div>
|
||||
<span class="mb-2 block text-sm font-medium">Theme</span>
|
||||
<div class="flex w-full rounded-md border border-border p-1">
|
||||
@@ -69,8 +65,7 @@
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="secondary" onclick={() => (open = false)}>Dismiss</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<div class="sc-form-actions">
|
||||
<Button type="button" variant="secondary" onclick={() => (open = false)}>Dismiss</Button>
|
||||
</div>
|
||||
</SharedSettingsDialog>
|
||||
@@ -1,5 +1,6 @@
|
||||
<script>
|
||||
import '../app.css';
|
||||
import '@gabriel20xx/shared-code/web-ui/styles.css';
|
||||
import '$lib/theme.svelte.js';
|
||||
import { QueryClientProvider } from '@tanstack/svelte-query';
|
||||
import { queryClient } from '$lib/query/queryClient.js';
|
||||
|
||||
Reference in new issue
Block a user