feat: add user credentials management and health monitoring features
- Implemented CredentialsDialog for updating user credentials. - Created auth store with functions for managing authentication state. - Added HealthWidget to display server health status. - Introduced health monitoring functionality with polling. - Developed AppShell layout to manage authentication and loading states. - Added SettingsDialog for user preferences including theme and language. - Created utility functions for list management and data fetching. - Implemented dashboard view mode preferences. - Integrated search functionality for filtering lists. - Established theme management with local storage support. - Added utility functions for class name management. - Configured SvelteKit for static site generation with fallback. - Set up Vite for development with proxy support for API calls. - Created About and List detail pages with data fetching and display. - Added favicon and updated project configuration files.
This commit is contained in:
1 parent
a4a3eeb5cc
commit
6c1ea2da47
80 files changed
No files matched your search
@@ -0,0 +1,61 @@
|
||||
async function request(url, options) {
|
||||
const res = await fetch(url, {
|
||||
...options,
|
||||
headers: options?.body ? { 'Content-Type': 'application/json', ...options?.headers } : options?.headers,
|
||||
});
|
||||
if (!res.ok) {
|
||||
let message = `HTTP ${res.status}`;
|
||||
try {
|
||||
const body = await res.json();
|
||||
// This backend's error responses are { error: "<category>", message: "<human text>" } -
|
||||
// message is the human-readable text; error is just a category label (e.g. "Unauthorized").
|
||||
if (body?.message) message = body.message;
|
||||
else if (body?.error) message = body.error;
|
||||
} catch {
|
||||
// Response body wasn't JSON (or was empty) - keep the generic status message.
|
||||
}
|
||||
throw new Error(message);
|
||||
}
|
||||
if (res.status === 204) return undefined;
|
||||
return res.json();
|
||||
}
|
||||
|
||||
async function getJson(url) {
|
||||
return request(url);
|
||||
}
|
||||
|
||||
export async function fetchOverview() {
|
||||
return getJson('/web/data');
|
||||
}
|
||||
|
||||
export async function fetchTechStack() {
|
||||
return getJson('/web/info');
|
||||
}
|
||||
|
||||
export async function fetchHealth() {
|
||||
const res = await fetch('/health');
|
||||
return { up: res.ok };
|
||||
}
|
||||
|
||||
export async function fetchAuthStatus() {
|
||||
return getJson('/api/auth/status');
|
||||
}
|
||||
|
||||
export async function setupAccount(username, email, password) {
|
||||
return request('/api/auth/setup', { method: 'POST', body: JSON.stringify({ username, email, password }) });
|
||||
}
|
||||
|
||||
export async function login(identifier, password) {
|
||||
return request('/api/auth/login', { method: 'POST', body: JSON.stringify({ identifier, password }) });
|
||||
}
|
||||
|
||||
export async function logout() {
|
||||
return request('/api/auth/logout', { method: 'POST' });
|
||||
}
|
||||
|
||||
export async function updateCredentials({ newUsername, newEmail, newPassword }) {
|
||||
return request('/api/auth/credentials', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ newUsername, newEmail, newPassword }),
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<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} />
|
||||
@@ -0,0 +1,31 @@
|
||||
<script>
|
||||
import { Table2 } from '@lucide/svelte';
|
||||
import { listFieldsFor, listItemsFor, fmtDate } from '$lib/features/lists/listHelpers.js';
|
||||
|
||||
let { list, fields, items, onClick } = $props();
|
||||
|
||||
const listFields = $derived(listFieldsFor(fields, list.id));
|
||||
const listItems = $derived(listItemsFor(items, list.id));
|
||||
</script>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="w-full rounded-lg border border-border bg-surface p-3 text-left transition-colors hover:bg-surface-hover"
|
||||
onclick={() => onClick(list)}
|
||||
>
|
||||
<div class="mb-2 flex items-center gap-2">
|
||||
<Table2 class="size-4 text-primary" />
|
||||
<span class="flex-1 truncate text-sm font-medium text-fg" title={list.name}>{list.name}</span>
|
||||
{#if list.isDeleted}
|
||||
<span class="rounded-full bg-danger/15 px-2 py-0.5 text-[11px] font-medium text-danger">Deleted</span>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-3 text-xs text-muted-fg">
|
||||
<span>{listFields.length} {listFields.length === 1 ? 'field' : 'fields'}</span>
|
||||
<span>{listItems.length} {listItems.length === 1 ? 'item' : 'items'}</span>
|
||||
</div>
|
||||
<div class="mt-1.5 text-xs text-muted-fg">
|
||||
Updated {fmtDate(list.effectiveUpdatedAt ?? list.updatedAt)}
|
||||
</div>
|
||||
</button>
|
||||
@@ -0,0 +1,20 @@
|
||||
<script>
|
||||
import { listFieldsFor, listItemsFor, fmtDate } from '$lib/features/lists/listHelpers.js';
|
||||
|
||||
let { list, fields, items, onClick } = $props();
|
||||
|
||||
const listFields = $derived(listFieldsFor(fields, list.id));
|
||||
const listItems = $derived(listItemsFor(items, list.id));
|
||||
</script>
|
||||
|
||||
<tr class="cursor-pointer border-t border-border hover:bg-surface-hover" onclick={() => onClick(list)}>
|
||||
<td class="py-2">
|
||||
<span class="font-medium text-fg">{list.name}</span>
|
||||
{#if list.isDeleted}
|
||||
<span class="ml-2 rounded-full bg-danger/15 px-2 py-0.5 text-[11px] font-medium text-danger">Deleted</span>
|
||||
{/if}
|
||||
</td>
|
||||
<td class="py-2 text-muted-fg">{listFields.length}</td>
|
||||
<td class="py-2 text-muted-fg">{listItems.length}</td>
|
||||
<td class="py-2 text-muted-fg">{fmtDate(list.effectiveUpdatedAt ?? list.updatedAt)}</td>
|
||||
</tr>
|
||||
@@ -0,0 +1,18 @@
|
||||
<script>
|
||||
import ListCard from './ListCard.svelte';
|
||||
|
||||
let { lists, fields, items, onSelect } = $props();
|
||||
</script>
|
||||
|
||||
{#if lists.length === 0}
|
||||
<div class="flex flex-col items-center gap-2 py-16 text-center">
|
||||
<div class="text-4xl">🔍</div>
|
||||
<div class="text-fg">No lists match your filters</div>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
|
||||
{#each lists as list (list.id)}
|
||||
<ListCard {list} {fields} {items} onClick={onSelect} />
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
@@ -0,0 +1,27 @@
|
||||
<script>
|
||||
import ListRow from './ListRow.svelte';
|
||||
|
||||
let { lists, fields, items, onSelect } = $props();
|
||||
</script>
|
||||
|
||||
<table class="w-full text-left text-sm">
|
||||
<thead>
|
||||
<tr class="text-muted-fg">
|
||||
<th class="py-2 font-medium">Name</th>
|
||||
<th class="py-2 font-medium">Fields</th>
|
||||
<th class="py-2 font-medium">Items</th>
|
||||
<th class="py-2 font-medium">Updated</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each lists as list (list.id)}
|
||||
<ListRow {list} {fields} {items} onClick={onSelect} />
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
{#if lists.length === 0}
|
||||
<div class="flex flex-col items-center gap-2 py-16 text-center">
|
||||
<div class="text-4xl">🔍</div>
|
||||
<div class="text-fg">No lists match your filters</div>
|
||||
</div>
|
||||
{/if}
|
||||
@@ -0,0 +1,39 @@
|
||||
<script module>
|
||||
import { cva } from 'class-variance-authority';
|
||||
|
||||
export const buttonVariants = cva(
|
||||
'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:size-4 [&_svg]:shrink-0',
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: 'bg-primary text-primary-fg hover:opacity-90',
|
||||
secondary: 'bg-surface text-fg hover:bg-surface-hover border border-border',
|
||||
ghost: 'hover:bg-surface-hover text-fg',
|
||||
outline: 'border border-border bg-transparent hover:bg-surface-hover text-fg',
|
||||
danger: 'bg-danger text-danger-fg hover:opacity-90',
|
||||
link: 'text-primary underline-offset-4 hover:underline',
|
||||
},
|
||||
size: {
|
||||
default: 'h-9 px-4 py-2',
|
||||
sm: 'h-8 rounded-md px-3 text-xs',
|
||||
lg: 'h-10 rounded-md px-6',
|
||||
icon: 'h-9 w-9',
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: 'default',
|
||||
size: 'default',
|
||||
},
|
||||
},
|
||||
);
|
||||
</script>
|
||||
|
||||
<script>
|
||||
import { cn } from '$lib/utils/cn.js';
|
||||
|
||||
let { class: className, variant, size, type = 'button', ref = $bindable(null), children, ...restProps } = $props();
|
||||
</script>
|
||||
|
||||
<button bind:this={ref} {type} class={cn(buttonVariants({ variant, size }), className)} {...restProps}>
|
||||
{@render children?.()}
|
||||
</button>
|
||||
@@ -0,0 +1,27 @@
|
||||
<script>
|
||||
import { Dialog } from 'bits-ui';
|
||||
import { X } from '@lucide/svelte';
|
||||
import { cn } from '$lib/utils/cn.js';
|
||||
|
||||
let { ref = $bindable(null), class: className, children, ...restProps } = $props();
|
||||
</script>
|
||||
|
||||
<Dialog.Portal>
|
||||
<Dialog.Overlay class="fixed inset-0 z-50 bg-black/50 animate-in fade-in-0" />
|
||||
<Dialog.Content
|
||||
bind:ref
|
||||
class={cn(
|
||||
'fixed left-1/2 top-1/2 z-50 max-h-[calc(100dvh-2rem)] w-[calc(100%-2rem)] max-w-lg -translate-x-1/2 -translate-y-1/2 overflow-y-auto rounded-lg border border-border bg-bg p-6 shadow-lg animate-in fade-in-0 zoom-in-95',
|
||||
className,
|
||||
)}
|
||||
{...restProps}
|
||||
>
|
||||
{@render children?.()}
|
||||
<Dialog.Close
|
||||
class="absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus-visible:outline-none"
|
||||
>
|
||||
<X class="size-4" />
|
||||
<span class="sr-only">Close</span>
|
||||
</Dialog.Close>
|
||||
</Dialog.Content>
|
||||
</Dialog.Portal>
|
||||
@@ -0,0 +1,9 @@
|
||||
<script>
|
||||
import { cn } from '$lib/utils/cn.js';
|
||||
|
||||
let { class: className, children, ...restProps } = $props();
|
||||
</script>
|
||||
|
||||
<div class={cn('mt-6 flex flex-col-reverse gap-2 sm:flex-row sm:justify-end', className)} {...restProps}>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
@@ -0,0 +1,9 @@
|
||||
<script>
|
||||
import { cn } from '$lib/utils/cn.js';
|
||||
|
||||
let { class: className, children, ...restProps } = $props();
|
||||
</script>
|
||||
|
||||
<div class={cn('mb-4 flex flex-col gap-1', className)} {...restProps}>
|
||||
{@render children?.()}
|
||||
</div>
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Dialog as DialogPrimitive } from 'bits-ui';
|
||||
|
||||
export const Dialog = DialogPrimitive.Root;
|
||||
export const DialogTrigger = DialogPrimitive.Trigger;
|
||||
export const DialogClose = DialogPrimitive.Close;
|
||||
|
||||
export { default as DialogContent } from './content.svelte';
|
||||
export { default as DialogHeader } from './header.svelte';
|
||||
export { default as DialogTitle } from './title.svelte';
|
||||
export { default as DialogFooter } from './footer.svelte';
|
||||
@@ -0,0 +1,10 @@
|
||||
<script>
|
||||
import { Dialog } from 'bits-ui';
|
||||
import { cn } from '$lib/utils/cn.js';
|
||||
|
||||
let { ref = $bindable(null), class: className, children, ...restProps } = $props();
|
||||
</script>
|
||||
|
||||
<Dialog.Title bind:ref class={cn('text-lg font-semibold', className)} {...restProps}>
|
||||
{@render children?.()}
|
||||
</Dialog.Title>
|
||||
@@ -0,0 +1,28 @@
|
||||
<script>
|
||||
import { DropdownMenu } from 'bits-ui';
|
||||
import { cn } from '$lib/utils/cn.js';
|
||||
|
||||
let {
|
||||
ref = $bindable(null),
|
||||
class: className,
|
||||
sideOffset = 6,
|
||||
align = 'end',
|
||||
children,
|
||||
...restProps
|
||||
} = $props();
|
||||
</script>
|
||||
|
||||
<DropdownMenu.Portal>
|
||||
<DropdownMenu.Content
|
||||
bind:ref
|
||||
{sideOffset}
|
||||
{align}
|
||||
class={cn(
|
||||
'z-50 min-w-[10rem] overflow-hidden rounded-md border border-border bg-surface p-1 text-fg shadow-lg animate-in fade-in-0 zoom-in-95',
|
||||
className,
|
||||
)}
|
||||
{...restProps}
|
||||
>
|
||||
{@render children?.()}
|
||||
</DropdownMenu.Content>
|
||||
</DropdownMenu.Portal>
|
||||
@@ -0,0 +1,8 @@
|
||||
import { DropdownMenu as DropdownMenuPrimitive } from 'bits-ui';
|
||||
|
||||
export const DropdownMenu = DropdownMenuPrimitive.Root;
|
||||
export const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger;
|
||||
|
||||
export { default as DropdownMenuContent } from './content.svelte';
|
||||
export { default as DropdownMenuItem } from './item.svelte';
|
||||
export { default as DropdownMenuSeparator } from './separator.svelte';
|
||||
@@ -0,0 +1,18 @@
|
||||
<script>
|
||||
import { DropdownMenu } from 'bits-ui';
|
||||
import { cn } from '$lib/utils/cn.js';
|
||||
|
||||
let { ref = $bindable(null), class: className, active = false, children, ...restProps } = $props();
|
||||
</script>
|
||||
|
||||
<DropdownMenu.Item
|
||||
bind:ref
|
||||
class={cn(
|
||||
'flex cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none data-highlighted:bg-surface-hover',
|
||||
active && 'text-primary font-medium',
|
||||
className,
|
||||
)}
|
||||
{...restProps}
|
||||
>
|
||||
{@render children?.()}
|
||||
</DropdownMenu.Item>
|
||||
@@ -0,0 +1,8 @@
|
||||
<script>
|
||||
import { DropdownMenu } from 'bits-ui';
|
||||
import { cn } from '$lib/utils/cn.js';
|
||||
|
||||
let { ref = $bindable(null), class: className, ...restProps } = $props();
|
||||
</script>
|
||||
|
||||
<DropdownMenu.Separator bind:ref class={cn('-mx-1 my-1 h-px bg-border', className)} {...restProps} />
|
||||
@@ -0,0 +1,93 @@
|
||||
<script>
|
||||
import { ChevronFirst, ChevronLast, ChevronLeft, ChevronRight } from '@lucide/svelte';
|
||||
import Button from './button.svelte';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './select';
|
||||
import { SimpleTooltip } from './tooltip';
|
||||
|
||||
let { page, pageSize, pageSizes = [12, 24, 48, 96], pageLength = 0, totalLength = 0, onPaging } = $props();
|
||||
|
||||
const hasPreviousPage = $derived(page > 1);
|
||||
const firstItemIndex = $derived((page - 1) * pageSize + 1);
|
||||
const lastItemIndex = $derived((page - 1) * pageSize + pageLength);
|
||||
const hasNextPage = $derived(page * pageSize < totalLength);
|
||||
|
||||
// Passed as `Select`'s `items` prop so the trigger shows the right label immediately, even
|
||||
// before the dropdown has ever been opened - bits-ui can't rely on `Select.Item` having
|
||||
// mounted to the DOM yet to read its label back off of it.
|
||||
const pageSizeItems = $derived(pageSizes.map((size) => ({ value: String(size), label: String(size) })));
|
||||
</script>
|
||||
|
||||
<div class="flex flex-wrap items-center justify-end gap-4 px-2 py-3 text-sm">
|
||||
<Select
|
||||
type="single"
|
||||
value={String(pageSize)}
|
||||
items={pageSizeItems}
|
||||
onValueChange={(value) => onPaging({ page: 1, pageSize: Number(value) })}
|
||||
>
|
||||
<SelectTrigger class="w-24">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{#each pageSizeItems as item (item.value)}
|
||||
<SelectItem value={item.value} label={item.label}>{item.label}</SelectItem>
|
||||
{/each}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<p class="text-muted-fg">
|
||||
{firstItemIndex.toLocaleString()}–{lastItemIndex.toLocaleString()} of {totalLength.toLocaleString()}
|
||||
</p>
|
||||
<div class="flex items-center gap-1">
|
||||
<SimpleTooltip label="First page">
|
||||
{#snippet children({ props })}
|
||||
<Button
|
||||
{...props}
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
disabled={!hasPreviousPage}
|
||||
onclick={() => onPaging({ page: 1, pageSize })}
|
||||
>
|
||||
<ChevronFirst class="size-4" />
|
||||
</Button>
|
||||
{/snippet}
|
||||
</SimpleTooltip>
|
||||
<SimpleTooltip label="Previous page">
|
||||
{#snippet children({ props })}
|
||||
<Button
|
||||
{...props}
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
disabled={!hasPreviousPage}
|
||||
onclick={() => onPaging({ page: page - 1, pageSize })}
|
||||
>
|
||||
<ChevronLeft class="size-4" />
|
||||
</Button>
|
||||
{/snippet}
|
||||
</SimpleTooltip>
|
||||
<SimpleTooltip label="Next page">
|
||||
{#snippet children({ props })}
|
||||
<Button
|
||||
{...props}
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
disabled={!hasNextPage}
|
||||
onclick={() => onPaging({ page: page + 1, pageSize })}
|
||||
>
|
||||
<ChevronRight class="size-4" />
|
||||
</Button>
|
||||
{/snippet}
|
||||
</SimpleTooltip>
|
||||
<SimpleTooltip label="Last page">
|
||||
{#snippet children({ props })}
|
||||
<Button
|
||||
{...props}
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
disabled={!hasNextPage}
|
||||
onclick={() => onPaging({ page: Math.max(1, Math.ceil(totalLength / pageSize)), pageSize })}
|
||||
>
|
||||
<ChevronLast class="size-4" />
|
||||
</Button>
|
||||
{/snippet}
|
||||
</SimpleTooltip>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,20 @@
|
||||
<script>
|
||||
import { Select } from 'bits-ui';
|
||||
import { cn } from '$lib/utils/cn.js';
|
||||
|
||||
let { ref = $bindable(null), class: className, sideOffset = 4, children, ...restProps } = $props();
|
||||
</script>
|
||||
|
||||
<Select.Portal>
|
||||
<Select.Content
|
||||
bind:ref
|
||||
{sideOffset}
|
||||
class={cn(
|
||||
'z-50 max-h-72 w-[var(--bits-select-anchor-width)] overflow-y-auto rounded-md border border-border bg-surface p-1 shadow-lg',
|
||||
className,
|
||||
)}
|
||||
{...restProps}
|
||||
>
|
||||
{@render children?.()}
|
||||
</Select.Content>
|
||||
</Select.Portal>
|
||||
@@ -0,0 +1,8 @@
|
||||
import { Select as SelectPrimitive } from 'bits-ui';
|
||||
|
||||
export const Select = SelectPrimitive.Root;
|
||||
export const SelectValue = SelectPrimitive.Value;
|
||||
|
||||
export { default as SelectTrigger } from './trigger.svelte';
|
||||
export { default as SelectContent } from './content.svelte';
|
||||
export { default as SelectItem } from './item.svelte';
|
||||
@@ -0,0 +1,25 @@
|
||||
<script>
|
||||
import { Select } from 'bits-ui';
|
||||
import { Check } from '@lucide/svelte';
|
||||
import { cn } from '$lib/utils/cn.js';
|
||||
|
||||
let { ref = $bindable(null), class: className, value, label, children: itemLabel, ...restProps } = $props();
|
||||
</script>
|
||||
|
||||
<Select.Item
|
||||
bind:ref
|
||||
{value}
|
||||
{label}
|
||||
class={cn(
|
||||
'flex cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none data-highlighted:bg-surface-hover',
|
||||
className,
|
||||
)}
|
||||
{...restProps}
|
||||
>
|
||||
{#snippet children({ selected })}
|
||||
{@render itemLabel?.()}
|
||||
{#if selected}
|
||||
<Check class="ml-auto size-4" />
|
||||
{/if}
|
||||
{/snippet}
|
||||
</Select.Item>
|
||||
@@ -0,0 +1,19 @@
|
||||
<script>
|
||||
import { Select } from 'bits-ui';
|
||||
import { ChevronDown } from '@lucide/svelte';
|
||||
import { cn } from '$lib/utils/cn.js';
|
||||
|
||||
let { ref = $bindable(null), class: className, children, ...restProps } = $props();
|
||||
</script>
|
||||
|
||||
<Select.Trigger
|
||||
bind:ref
|
||||
class={cn(
|
||||
'flex h-9 items-center justify-between gap-2 rounded-md border border-border bg-bg px-3 text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50',
|
||||
className,
|
||||
)}
|
||||
{...restProps}
|
||||
>
|
||||
{@render children?.()}
|
||||
<ChevronDown class="size-4 opacity-60" />
|
||||
</Select.Trigger>
|
||||
@@ -0,0 +1,20 @@
|
||||
<script>
|
||||
import { Tooltip } from 'bits-ui';
|
||||
import { cn } from '$lib/utils/cn.js';
|
||||
|
||||
let { ref = $bindable(null), class: className, sideOffset = 6, children, ...restProps } = $props();
|
||||
</script>
|
||||
|
||||
<Tooltip.Portal>
|
||||
<Tooltip.Content
|
||||
bind:ref
|
||||
{sideOffset}
|
||||
class={cn(
|
||||
'z-50 overflow-hidden rounded-md border border-border bg-surface px-3 py-1.5 text-xs text-fg shadow-md animate-in fade-in-0 zoom-in-95',
|
||||
className,
|
||||
)}
|
||||
{...restProps}
|
||||
>
|
||||
{@render children?.()}
|
||||
</Tooltip.Content>
|
||||
</Tooltip.Portal>
|
||||
@@ -0,0 +1,5 @@
|
||||
import { Tooltip as TooltipPrimitive } from 'bits-ui';
|
||||
|
||||
export const TooltipProvider = TooltipPrimitive.Provider;
|
||||
|
||||
export { default as SimpleTooltip } from './simple-tooltip.svelte';
|
||||
@@ -0,0 +1,15 @@
|
||||
<script>
|
||||
import { Tooltip } from 'bits-ui';
|
||||
import TooltipContent from './content.svelte';
|
||||
|
||||
let { label, children } = $props();
|
||||
</script>
|
||||
|
||||
<Tooltip.Root>
|
||||
<Tooltip.Trigger>
|
||||
{#snippet child({ props })}
|
||||
{@render children({ props })}
|
||||
{/snippet}
|
||||
</Tooltip.Trigger>
|
||||
<TooltipContent>{label}</TooltipContent>
|
||||
</Tooltip.Root>
|
||||
@@ -0,0 +1,48 @@
|
||||
<script>
|
||||
import { createQuery } from '@tanstack/svelte-query';
|
||||
import { fetchTechStack } from '$lib/api.js';
|
||||
|
||||
const FRONTEND_TECH_STACK = __FRONTEND_TECH_STACK__;
|
||||
|
||||
const techStackQuery = createQuery(() => ({
|
||||
queryKey: ['TechStack'],
|
||||
queryFn: fetchTechStack,
|
||||
}));
|
||||
|
||||
const techStack = $derived(techStackQuery.data);
|
||||
</script>
|
||||
|
||||
{#snippet infoRow(label, value)}
|
||||
<div class="flex items-center justify-between gap-2 py-1 text-sm">
|
||||
<span class="text-muted-fg">{label}</span>
|
||||
<span class="font-mono text-xs text-fg">{value}</span>
|
||||
</div>
|
||||
{/snippet}
|
||||
|
||||
<div class="rounded-lg border border-border bg-surface p-4">
|
||||
<h3 class="mb-2 text-sm font-medium text-fg">Tech stack</h3>
|
||||
|
||||
{#if techStackQuery.isLoading}
|
||||
<p class="text-sm text-muted-fg">Loading tech stack…</p>
|
||||
{/if}
|
||||
{#if techStackQuery.error}
|
||||
<p class="text-sm text-danger">{techStackQuery.error.message}</p>
|
||||
{/if}
|
||||
|
||||
{#if techStack}
|
||||
<div class="mt-3 grid gap-6 sm:grid-cols-2">
|
||||
<div>
|
||||
<h4 class="mb-1 text-xs font-medium uppercase text-muted-fg">Backend</h4>
|
||||
{#each techStack.stack as entry (entry.label)}
|
||||
{@render infoRow(entry.label, entry.value)}
|
||||
{/each}
|
||||
</div>
|
||||
<div>
|
||||
<h4 class="mb-1 text-xs font-medium uppercase text-muted-fg">Frontend</h4>
|
||||
{#each FRONTEND_TECH_STACK as dep (dep.name)}
|
||||
{@render infoRow(dep.name, dep.version)}
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
@@ -0,0 +1,119 @@
|
||||
<script>
|
||||
import { Table2 } from '@lucide/svelte';
|
||||
import Button from '$lib/components/ui/button.svelte';
|
||||
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;
|
||||
}
|
||||
}
|
||||
</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>
|
||||
@@ -0,0 +1,111 @@
|
||||
<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>
|
||||
@@ -0,0 +1,68 @@
|
||||
import { createMutation, createQuery, useQueryClient } from '@tanstack/svelte-query';
|
||||
import { getContext, setContext } from 'svelte';
|
||||
import { fetchAuthStatus, login, logout, setupAccount, updateCredentials } from '$lib/api.js';
|
||||
|
||||
const AUTH_STATUS_KEY = ['AuthStatus'];
|
||||
const AUTH_CONTEXT_KEY = Symbol('auth');
|
||||
|
||||
export function createAuthStore() {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const statusQuery = createQuery(() => ({
|
||||
queryKey: AUTH_STATUS_KEY,
|
||||
queryFn: fetchAuthStatus,
|
||||
}));
|
||||
const setupMutation = createMutation(() => ({
|
||||
mutationFn: ({ username, email, password }) => setupAccount(username, email, password),
|
||||
}));
|
||||
const loginMutation = createMutation(() => ({
|
||||
mutationFn: ({ identifier, password }) => login(identifier, password),
|
||||
}));
|
||||
const logoutMutation = createMutation(() => ({
|
||||
mutationFn: () => logout(),
|
||||
}));
|
||||
const updateCredentialsMutation = createMutation(() => ({
|
||||
mutationFn: (input) => updateCredentials(input),
|
||||
}));
|
||||
|
||||
const refresh = () => queryClient.invalidateQueries({ queryKey: AUTH_STATUS_KEY });
|
||||
|
||||
const store = {
|
||||
get status() {
|
||||
return statusQuery.data;
|
||||
},
|
||||
get loading() {
|
||||
return statusQuery.isLoading;
|
||||
},
|
||||
get error() {
|
||||
return statusQuery.error;
|
||||
},
|
||||
async setup(username, email, password) {
|
||||
await setupMutation.mutateAsync({ username, email, password });
|
||||
await refresh();
|
||||
},
|
||||
async login(identifier, password) {
|
||||
await loginMutation.mutateAsync({ identifier, password });
|
||||
await refresh();
|
||||
},
|
||||
async logout() {
|
||||
await logoutMutation.mutateAsync();
|
||||
await refresh();
|
||||
},
|
||||
async updateCredentials(input) {
|
||||
await updateCredentialsMutation.mutateAsync(input);
|
||||
await refresh();
|
||||
},
|
||||
};
|
||||
|
||||
setContext(AUTH_CONTEXT_KEY, store);
|
||||
return store;
|
||||
}
|
||||
|
||||
export function useAuth() {
|
||||
const ctx = getContext(AUTH_CONTEXT_KEY);
|
||||
if (!ctx) {
|
||||
throw new Error('useAuth() must be called within the root layout that calls createAuthStore()');
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<script>
|
||||
import { AlertTriangle, CheckCircle2, HelpCircle } from '@lucide/svelte';
|
||||
import Button from '$lib/components/ui/button.svelte';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogFooter,
|
||||
DialogClose,
|
||||
} from '$lib/components/ui/dialog';
|
||||
import { SimpleTooltip } from '$lib/components/ui/tooltip';
|
||||
import { createHealth } from './health.svelte.js';
|
||||
|
||||
const icons = { up: CheckCircle2, down: AlertTriangle, unknown: HelpCircle };
|
||||
const statusColor = { up: 'text-success', down: 'text-danger', unknown: 'text-muted-fg' };
|
||||
const statusLabel = { up: 'up', down: 'unreachable', unknown: 'checking…' };
|
||||
|
||||
const health = createHealth();
|
||||
let open = $state(false);
|
||||
|
||||
const Icon = $derived(icons[health.status]);
|
||||
</script>
|
||||
|
||||
<Dialog bind:open>
|
||||
<SimpleTooltip label={`CollabTable server is ${statusLabel[health.status]}`}>
|
||||
{#snippet children({ props })}
|
||||
<Button
|
||||
{...props}
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onclick={() => (open = true)}
|
||||
class={statusColor[health.status]}
|
||||
aria-label="Status"
|
||||
>
|
||||
<Icon class="size-5" />
|
||||
</Button>
|
||||
{/snippet}
|
||||
</SimpleTooltip>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Status: CollabTable server is {statusLabel[health.status]}</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div class="flex items-center gap-2 text-sm">
|
||||
<Icon class={`size-4 ${statusColor[health.status]}`} />
|
||||
<span class="text-muted-fg">GET /health</span>
|
||||
<span class={statusColor[health.status]}>{statusLabel[health.status]}</span>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<DialogClose>
|
||||
{#snippet child({ props })}
|
||||
<Button variant="secondary" {...props}>Dismiss</Button>
|
||||
{/snippet}
|
||||
</DialogClose>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
@@ -0,0 +1,24 @@
|
||||
import { createQuery } from '@tanstack/svelte-query';
|
||||
import { fetchHealth } from '$lib/api.js';
|
||||
|
||||
const pollIntervalMs = 10_000;
|
||||
|
||||
export function createHealth() {
|
||||
const query = createQuery(() => ({
|
||||
queryKey: ['Health'],
|
||||
queryFn: fetchHealth,
|
||||
refetchInterval: pollIntervalMs,
|
||||
}));
|
||||
|
||||
const status = $derived.by(() => {
|
||||
if (query.error) return 'down';
|
||||
if (!query.data) return 'unknown';
|
||||
return query.data.up ? 'up' : 'down';
|
||||
});
|
||||
|
||||
return {
|
||||
get status() {
|
||||
return status;
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<script>
|
||||
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';
|
||||
|
||||
let { children } = $props();
|
||||
|
||||
const auth = createAuthStore();
|
||||
</script>
|
||||
|
||||
<Tooltip.Provider delayDuration={300}>
|
||||
{#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}
|
||||
<div class="flex min-h-screen flex-col">
|
||||
<Header />
|
||||
<main class="flex min-w-0 flex-1 flex-col">
|
||||
{@render children?.()}
|
||||
</main>
|
||||
</div>
|
||||
{/if}
|
||||
</Tooltip.Provider>
|
||||
@@ -0,0 +1,76 @@
|
||||
<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 { 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';
|
||||
|
||||
let { open = $bindable(false) } = $props();
|
||||
|
||||
const languageItems = languages.map((language) => ({ value: language.id, label: language.label }));
|
||||
</script>
|
||||
|
||||
<Dialog bind:open>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Settings</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div>
|
||||
<span class="mb-2 block text-sm font-medium">Theme</span>
|
||||
<div class="flex w-full rounded-md border border-border p-1">
|
||||
<Button
|
||||
type="button"
|
||||
variant={themeState.mode === 'light' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
class="flex-1 gap-1.5"
|
||||
onclick={() => themeState.setMode('light')}
|
||||
>
|
||||
<Sun class="size-4" />
|
||||
Light
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant={themeState.mode === 'dark' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
class="flex-1 gap-1.5"
|
||||
onclick={() => themeState.setMode('dark')}
|
||||
>
|
||||
<Moon class="size-4" />
|
||||
Dark
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant={themeState.mode === 'system' ? 'secondary' : 'ghost'}
|
||||
size="sm"
|
||||
class="flex-1 gap-1.5"
|
||||
onclick={() => themeState.setMode('system')}
|
||||
>
|
||||
<SunMoon class="size-4" />
|
||||
System
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5">
|
||||
<label for="settings-language" class="mb-2 block text-sm font-medium">Language</label>
|
||||
<Select
|
||||
type="single"
|
||||
value={currentLanguage()}
|
||||
items={languageItems}
|
||||
onValueChange={(value) => setLanguage(value)}
|
||||
>
|
||||
<SelectTrigger id="settings-language" class="w-full">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{#each languageItems as item (item.value)}
|
||||
<SelectItem value={item.value} label={item.label}>{item.label}</SelectItem>
|
||||
{/each}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button type="button" variant="secondary" onclick={() => (open = false)}>Dismiss</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
@@ -0,0 +1,21 @@
|
||||
export function listFieldsFor(fields, listId) {
|
||||
return fields.filter((f) => f.listId === listId && !f.isDeleted).sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
||||
}
|
||||
|
||||
export function listItemsFor(items, listId) {
|
||||
return items.filter((i) => i.listId === listId && !i.isDeleted);
|
||||
}
|
||||
|
||||
export function itemValuesFor(values, itemId) {
|
||||
return values.filter((v) => v.itemId === itemId);
|
||||
}
|
||||
|
||||
export function valueFor(values, itemId, fieldId) {
|
||||
return values.find((v) => v.itemId === itemId && v.fieldId === fieldId)?.value ?? null;
|
||||
}
|
||||
|
||||
export function fmtDate(v) {
|
||||
if (v === null || v === undefined) return '—';
|
||||
const d = new Date(v);
|
||||
return Number.isNaN(d.getTime()) ? '—' : d.toLocaleString();
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { createQuery } from '@tanstack/svelte-query';
|
||||
import { fetchOverview } from '$lib/api.js';
|
||||
|
||||
const pollIntervalMs = 5_000;
|
||||
|
||||
export function createOverviewData() {
|
||||
const query = createQuery(() => ({
|
||||
queryKey: ['Overview'],
|
||||
queryFn: fetchOverview,
|
||||
refetchInterval: pollIntervalMs,
|
||||
}));
|
||||
|
||||
const lists = $derived(query.data?.lists ?? []);
|
||||
const fields = $derived(query.data?.fields ?? []);
|
||||
const items = $derived(query.data?.items ?? []);
|
||||
const values = $derived(query.data?.values ?? []);
|
||||
const stats = $derived(query.data?.stats ?? { lists: 0, fields: 0, items: 0, values: 0 });
|
||||
|
||||
return {
|
||||
get lists() {
|
||||
return lists;
|
||||
},
|
||||
get fields() {
|
||||
return fields;
|
||||
},
|
||||
get items() {
|
||||
return items;
|
||||
},
|
||||
get values() {
|
||||
return values;
|
||||
},
|
||||
get stats() {
|
||||
return stats;
|
||||
},
|
||||
get isLoading() {
|
||||
return query.isLoading;
|
||||
},
|
||||
get error() {
|
||||
return query.error;
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { browser } from '$app/environment';
|
||||
|
||||
export const languages = [
|
||||
{ id: 'ar', label: 'العربية' },
|
||||
{ id: 'ca', label: 'Català' },
|
||||
{ id: 'de', label: 'Deutsch' },
|
||||
{ id: 'en', label: 'English' },
|
||||
{ id: 'es', label: 'Español' },
|
||||
{ id: 'fr', label: 'Français' },
|
||||
{ id: 'hi', label: 'हिन्दी' },
|
||||
{ id: 'it', label: 'Italiano' },
|
||||
{ id: 'ja', label: '日本語' },
|
||||
{ id: 'nl', label: 'Nederlands' },
|
||||
{ id: 'pt', label: 'Português' },
|
||||
{ id: 'ru', label: 'Русский' },
|
||||
{ id: 'tr', label: 'Türkçe' },
|
||||
{ id: 'uk', label: 'Українська' },
|
||||
{ id: 'zh', label: '中文' },
|
||||
];
|
||||
|
||||
const defaultLanguage = 'en';
|
||||
const storageKey = 'collabtable-language';
|
||||
const supportedIds = new Set(languages.map((language) => language.id));
|
||||
const rtlLanguages = new Set(['ar']);
|
||||
|
||||
/** @param {string | null | undefined} value @returns {value is string} */
|
||||
function isLanguage(value) {
|
||||
return Boolean(value && supportedIds.has(value));
|
||||
}
|
||||
|
||||
function getInitialLanguage() {
|
||||
if (!browser) return defaultLanguage;
|
||||
|
||||
const stored = localStorage.getItem(storageKey);
|
||||
if (isLanguage(stored)) return stored;
|
||||
|
||||
const automatic = navigator.language?.split('-')[0];
|
||||
return isLanguage(automatic) ? automatic : defaultLanguage;
|
||||
}
|
||||
|
||||
/** @param {string} language */
|
||||
function applyLanguage(language) {
|
||||
document.documentElement.lang = language;
|
||||
document.documentElement.dir = rtlLanguages.has(language) ? 'rtl' : 'ltr';
|
||||
}
|
||||
|
||||
let selectedLanguage = $state(getInitialLanguage());
|
||||
|
||||
export function currentLanguage() {
|
||||
return selectedLanguage;
|
||||
}
|
||||
|
||||
/** @param {string} language */
|
||||
export function setLanguage(language) {
|
||||
if (!isLanguage(language)) return;
|
||||
|
||||
selectedLanguage = language;
|
||||
if (browser) {
|
||||
localStorage.setItem(storageKey, language);
|
||||
applyLanguage(language);
|
||||
}
|
||||
}
|
||||
|
||||
if (browser) applyLanguage(currentLanguage());
|
||||
@@ -0,0 +1,22 @@
|
||||
const STORAGE_KEY = 'collabtable-dashboard-view-mode';
|
||||
|
||||
function readStoredViewMode() {
|
||||
if (typeof window === 'undefined') return 'grid';
|
||||
return window.localStorage.getItem(STORAGE_KEY) === 'list' ? 'list' : 'grid';
|
||||
}
|
||||
|
||||
export function createDashboardViewMode() {
|
||||
let mode = $state(readStoredViewMode());
|
||||
|
||||
function setMode(value) {
|
||||
window.localStorage.setItem(STORAGE_KEY, value);
|
||||
mode = value;
|
||||
}
|
||||
|
||||
return {
|
||||
get mode() {
|
||||
return mode;
|
||||
},
|
||||
setMode,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { QueryClient } from '@tanstack/svelte-query';
|
||||
|
||||
export const queryClient = new QueryClient({
|
||||
defaultOptions: { queries: { retry: false, refetchOnWindowFocus: false } },
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
export const searchState = $state({ query: '' });
|
||||
|
||||
export function filterListsBySearch(lists, query) {
|
||||
if (!query || !query.trim()) return lists;
|
||||
const needle = query.trim().toLowerCase();
|
||||
return lists.filter((l) => l.name.toLowerCase().includes(needle));
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { browser } from '$app/environment';
|
||||
|
||||
const STORAGE_KEY = 'collabtable-theme';
|
||||
|
||||
function prefersDarkMediaQuery() {
|
||||
return browser && window.matchMedia ? window.matchMedia('(prefers-color-scheme: dark)') : undefined;
|
||||
}
|
||||
|
||||
function loadInitialMode() {
|
||||
if (!browser) return 'system';
|
||||
const stored = localStorage.getItem(STORAGE_KEY);
|
||||
return stored === 'light' || stored === 'dark' || stored === 'system' ? stored : 'system';
|
||||
}
|
||||
|
||||
let mode = $state(loadInitialMode());
|
||||
let systemPrefersDark = $state(prefersDarkMediaQuery()?.matches ?? false);
|
||||
|
||||
export const themeState = {
|
||||
get mode() {
|
||||
return mode;
|
||||
},
|
||||
get isDark() {
|
||||
return mode === 'system' ? systemPrefersDark : mode === 'dark';
|
||||
},
|
||||
get value() {
|
||||
return themeState.isDark ? 'dark' : 'light';
|
||||
},
|
||||
setMode(next) {
|
||||
mode = next;
|
||||
if (browser) localStorage.setItem(STORAGE_KEY, next);
|
||||
},
|
||||
};
|
||||
|
||||
if (browser) {
|
||||
$effect.root(() => {
|
||||
$effect(() => {
|
||||
document.documentElement.setAttribute('data-theme', themeState.value);
|
||||
});
|
||||
|
||||
const mql = prefersDarkMediaQuery();
|
||||
if (mql) {
|
||||
mql.addEventListener('change', () => {
|
||||
systemPrefersDark = mql.matches;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { clsx } from 'clsx';
|
||||
import { twMerge } from 'tailwind-merge';
|
||||
|
||||
export function cn(...inputs) {
|
||||
return twMerge(clsx(inputs));
|
||||
}
|
||||
Reference in new issue
Block a user