The /geschichten list page now renders one removable chip per active person filter and lets users add more via the existing typeahead. The URL uses repeated ?personId= params (matching the documents tag filter), which the regenerated API client passes straight through to the backend's new array-bound endpoint. New translation keys cover the chip remove aria-label, the AND hint shown while picking, and the multi-person empty state.
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { error } from '@sveltejs/kit';
|
|
import { createApiClient } from '$lib/api.server';
|
|
import { getErrorMessage } from '$lib/errors';
|
|
import type { components } from '$lib/generated/api';
|
|
import type { PageServerLoad } from './$types';
|
|
|
|
type Person = components['schemas']['Person'];
|
|
|
|
export const load: PageServerLoad = async ({ url, fetch }) => {
|
|
const api = createApiClient(fetch);
|
|
const personIds = url.searchParams.getAll('personId');
|
|
const documentId = url.searchParams.get('documentId') ?? undefined;
|
|
|
|
const [listResult, ...personResults] = await Promise.all([
|
|
api.GET('/api/geschichten', {
|
|
params: {
|
|
query: {
|
|
status: 'PUBLISHED',
|
|
personId: personIds.length ? personIds : undefined,
|
|
documentId
|
|
}
|
|
}
|
|
}),
|
|
...personIds.map((id) => api.GET('/api/persons/{id}', { params: { path: { id } } }))
|
|
]);
|
|
|
|
if (!listResult.response.ok) {
|
|
const code = (listResult.error as unknown as { code?: string })?.code;
|
|
throw error(listResult.response.status, getErrorMessage(code));
|
|
}
|
|
|
|
const personFilters = personResults
|
|
.filter((r) => r && r.response.ok && r.data)
|
|
.map((r) => r!.data!) as Person[];
|
|
|
|
return {
|
|
geschichten: listResult.data ?? [],
|
|
personFilters,
|
|
documentFilter: documentId ?? null
|
|
};
|
|
};
|