2026-07-31 18:26:08 +02:00
|
|
|
<script>
|
|
|
|
|
import { goto } from '$app/navigation';
|
|
|
|
|
import { resolve } from '$app/paths';
|
|
|
|
|
import { ArrowDown, ArrowUp, LayoutGrid, List, Search, X } from '@lucide/svelte';
|
|
|
|
|
import { createOverviewData } from '$lib/features/lists/listsData.svelte.js';
|
|
|
|
|
import { searchState, filterListsBySearch } from '$lib/search.svelte.js';
|
|
|
|
|
import { createDashboardViewMode } from '$lib/preferences/viewMode.svelte.js';
|
|
|
|
|
import Button from '$lib/components/ui/button.svelte';
|
|
|
|
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '$lib/components/ui/select';
|
|
|
|
|
import Paginator from '$lib/components/ui/paginator.svelte';
|
|
|
|
|
import ListsGrid from '$lib/components/lists/ListsGrid.svelte';
|
|
|
|
|
import ListsTable from '$lib/components/lists/ListsTable.svelte';
|
|
|
|
|
|
|
|
|
|
const SORT_FIELDS = [
|
|
|
|
|
{ field: 'name', label: 'Name' },
|
|
|
|
|
{ field: 'created', label: 'Created' },
|
|
|
|
|
{ field: 'updated', label: 'Updated' },
|
|
|
|
|
];
|
|
|
|
|
|
2026-07-31 19:29:56 +02:00
|
|
|
// 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 sortItems = SORT_FIELDS.map((s) => ({ value: s.field, label: s.label }));
|
|
|
|
|
|
2026-07-31 18:26:08 +02:00
|
|
|
const overview = createOverviewData();
|
|
|
|
|
const viewMode = createDashboardViewMode();
|
|
|
|
|
|
|
|
|
|
let sortField = $state('name');
|
|
|
|
|
let sortDir = $state('asc');
|
|
|
|
|
let page = $state(1);
|
|
|
|
|
let pageSize = $state(24);
|
|
|
|
|
|
|
|
|
|
function sortLists(lists, field, dir) {
|
|
|
|
|
const sorted = [...lists].sort((a, b) => {
|
|
|
|
|
if (field === 'name') return a.name.localeCompare(b.name);
|
|
|
|
|
if (field === 'created') return (a.createdAt ?? 0) - (b.createdAt ?? 0);
|
|
|
|
|
return (a.effectiveUpdatedAt ?? a.updatedAt ?? 0) - (b.effectiveUpdatedAt ?? b.updatedAt ?? 0);
|
|
|
|
|
});
|
|
|
|
|
return dir === 'desc' ? sorted.reverse() : sorted;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let searched = $derived(filterListsBySearch(overview.lists, searchState.query));
|
|
|
|
|
let sorted = $derived(sortLists(searched, sortField, sortDir));
|
|
|
|
|
let pageItems = $derived(sorted.slice((page - 1) * pageSize, (page - 1) * pageSize + pageSize));
|
|
|
|
|
|
|
|
|
|
$effect(() => {
|
|
|
|
|
void searchState.query;
|
|
|
|
|
void sortField;
|
|
|
|
|
void sortDir;
|
|
|
|
|
page = 1;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function goToList(list) {
|
|
|
|
|
void goto(resolve('/lists/[id]', { id: list.id }));
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div class="flex-1 p-4">
|
|
|
|
|
<div class="mb-4 grid grid-cols-2 gap-3 sm:grid-cols-4">
|
|
|
|
|
<div class="rounded-lg border border-border bg-surface p-3">
|
|
|
|
|
<div class="text-xs text-muted-fg">Lists</div>
|
|
|
|
|
<div class="mt-1 text-lg font-semibold text-fg">{overview.stats.lists}</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="rounded-lg border border-border bg-surface p-3">
|
|
|
|
|
<div class="text-xs text-muted-fg">Fields</div>
|
|
|
|
|
<div class="mt-1 text-lg font-semibold text-fg">{overview.stats.fields}</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="rounded-lg border border-border bg-surface p-3">
|
|
|
|
|
<div class="text-xs text-muted-fg">Items</div>
|
|
|
|
|
<div class="mt-1 text-lg font-semibold text-fg">{overview.stats.items}</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="rounded-lg border border-border bg-surface p-3">
|
|
|
|
|
<div class="text-xs text-muted-fg">Values</div>
|
|
|
|
|
<div class="mt-1 text-lg font-semibold text-fg">{overview.stats.values}</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{#if overview.isLoading}
|
|
|
|
|
<div class="flex items-center gap-3 py-10 text-sm text-muted-fg">
|
|
|
|
|
<span class="inline-block h-4 w-4 animate-spin rounded-full border-2 border-primary border-t-transparent"></span>
|
|
|
|
|
Loading lists…
|
|
|
|
|
</div>
|
|
|
|
|
{:else if overview.error}
|
|
|
|
|
<p class="text-sm text-danger">{overview.error.message}</p>
|
|
|
|
|
{:else}
|
|
|
|
|
<div class="mb-3 flex flex-wrap items-center gap-2">
|
|
|
|
|
<div class="relative min-w-0 flex-1 basis-full sm:basis-auto">
|
|
|
|
|
<Search class="pointer-events-none absolute left-2.5 top-1/2 size-4 -translate-y-1/2 text-muted-fg" />
|
|
|
|
|
<input
|
|
|
|
|
type="search"
|
|
|
|
|
bind:value={searchState.query}
|
|
|
|
|
placeholder="Search lists…"
|
|
|
|
|
autocapitalize="none"
|
|
|
|
|
class="h-9 w-full rounded-md border border-border bg-bg pl-8 pr-8 text-sm text-fg outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
|
|
|
|
/>
|
|
|
|
|
{#if searchState.query}
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onclick={() => (searchState.query = '')}
|
|
|
|
|
title="Clear search"
|
|
|
|
|
class="absolute right-2 top-1/2 -translate-y-1/2 text-muted-fg hover:text-fg"
|
|
|
|
|
>
|
|
|
|
|
<X class="size-4" />
|
|
|
|
|
</button>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-07-31 19:29:56 +02:00
|
|
|
<Select type="single" value={sortField} items={sortItems} onValueChange={(field) => (sortField = field)}>
|
2026-07-31 18:26:08 +02:00
|
|
|
<SelectTrigger class="min-w-0 flex-1 sm:w-44 sm:flex-none">
|
|
|
|
|
<SelectValue />
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
<SelectContent>
|
2026-07-31 19:29:56 +02:00
|
|
|
{#each sortItems as item (item.value)}
|
|
|
|
|
<SelectItem value={item.value} label={item.label}>{item.label}</SelectItem>
|
2026-07-31 18:26:08 +02:00
|
|
|
{/each}
|
|
|
|
|
</SelectContent>
|
|
|
|
|
</Select>
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="icon"
|
|
|
|
|
aria-label="Toggle sort direction"
|
|
|
|
|
onclick={() => (sortDir = sortDir === 'asc' ? 'desc' : 'asc')}
|
|
|
|
|
>
|
|
|
|
|
{#if sortDir === 'desc'}
|
|
|
|
|
<ArrowDown class="size-4" />
|
|
|
|
|
{:else}
|
|
|
|
|
<ArrowUp class="size-4" />
|
|
|
|
|
{/if}
|
|
|
|
|
</Button>
|
|
|
|
|
|
|
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="icon"
|
|
|
|
|
aria-label={viewMode.mode === 'grid' ? 'Switch to list view' : 'Switch to grid view'}
|
|
|
|
|
onclick={() => viewMode.setMode(viewMode.mode === 'grid' ? 'list' : 'grid')}
|
|
|
|
|
>
|
|
|
|
|
{#if viewMode.mode === 'grid'}
|
|
|
|
|
<LayoutGrid class="size-4" />
|
|
|
|
|
{:else}
|
|
|
|
|
<List class="size-4" />
|
|
|
|
|
{/if}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="overflow-x-auto rounded-lg border border-border bg-bg p-3">
|
|
|
|
|
{#if viewMode.mode === 'list'}
|
|
|
|
|
<ListsTable lists={pageItems} fields={overview.fields} items={overview.items} onSelect={goToList} />
|
|
|
|
|
{:else}
|
|
|
|
|
<ListsGrid lists={pageItems} fields={overview.fields} items={overview.items} onSelect={goToList} />
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<Paginator
|
|
|
|
|
{page}
|
|
|
|
|
{pageSize}
|
|
|
|
|
pageLength={pageItems.length}
|
|
|
|
|
totalLength={sorted.length}
|
|
|
|
|
onPaging={(e) => {
|
|
|
|
|
page = e.page;
|
|
|
|
|
pageSize = e.pageSize;
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|