feat(persons): enrich /persons list with stats bar, life dates, doc count chip

Load /api/stats in parallel; PersonsStatsBar shows totals; person cards
show alias, life date range, and document count badge.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-03-29 19:52:37 +02:00
parent 3abdf9bb68
commit f4c99cabd5
5 changed files with 119 additions and 25 deletions

View File

@@ -2,17 +2,30 @@ import { error } from '@sveltejs/kit';
import { createApiClient } from '$lib/api.server';
import { getErrorMessage } from '$lib/errors';
export async function load({ url, fetch }) {
export async function load({ url, fetch, locals }) {
const q = url.searchParams.get('q') || '';
const api = createApiClient(fetch);
const result = await api.GET('/api/persons', {
params: { query: { q: q || undefined } }
});
const canWrite =
(locals.user as { groups?: { permissions: string[] }[] } | undefined)?.groups?.some((g) =>
g.permissions.includes('WRITE_ALL')
) ?? false;
if (!result.response.ok) {
throw error(result.response.status, getErrorMessage(undefined));
const [personsResult, statsResult] = await Promise.all([
api.GET('/api/persons', { params: { query: { q: q || undefined } } }),
api.GET('/api/stats', {})
]);
if (!personsResult.response.ok) {
throw error(personsResult.response.status, getErrorMessage(undefined));
}
return { persons: result.data!, q };
const stats = statsResult.response.ok
? {
totalPersons: statsResult.data!.totalPersons ?? 0,
totalDocuments: statsResult.data!.totalDocuments ?? 0
}
: { totalPersons: 0, totalDocuments: 0 };
return { persons: personsResult.data!, stats, q, canWrite };
}