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} />
|
||||
Reference in new issue
Block a user