feat(search): read sort/dir/tagQ from URL and unwrap DocumentSearchResult envelope
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -13,6 +13,9 @@ export async function load({ url, fetch }) {
|
||||
const senderId = url.searchParams.get('senderId') || '';
|
||||
const receiverId = url.searchParams.get('receiverId') || '';
|
||||
const tags = url.searchParams.getAll('tag');
|
||||
const sort = url.searchParams.get('sort') || 'DATE';
|
||||
const dir = url.searchParams.get('dir') || 'desc';
|
||||
const tagQ = url.searchParams.get('tagQ') || '';
|
||||
|
||||
const isDashboard = !q && !from && !to && !senderId && !receiverId && !tags.length;
|
||||
|
||||
@@ -30,7 +33,10 @@ export async function load({ url, fetch }) {
|
||||
to: to || undefined,
|
||||
senderId: senderId || undefined,
|
||||
receiverId: receiverId || undefined,
|
||||
tag: tags.length ? tags : undefined
|
||||
tag: tags.length ? tags : undefined,
|
||||
tagQ: tagQ || undefined,
|
||||
sort: sort as 'DATE' | 'TITLE' | 'SENDER' | 'RECEIVER' | 'UPLOAD_DATE',
|
||||
dir: dir || undefined
|
||||
}
|
||||
}
|
||||
}),
|
||||
@@ -44,7 +50,9 @@ export async function load({ url, fetch }) {
|
||||
throw redirect(302, '/login');
|
||||
}
|
||||
|
||||
const documents: Document[] = docsResult?.data ?? [];
|
||||
const searchResult = docsResult?.data as { documents?: Document[]; total?: number } | null;
|
||||
const documents: Document[] = searchResult?.documents ?? [];
|
||||
const total: number = searchResult?.total ?? 0;
|
||||
const allPersons = (personsResult.data ?? []) as {
|
||||
id: string;
|
||||
firstName: string;
|
||||
@@ -80,6 +88,7 @@ export async function load({ url, fetch }) {
|
||||
return {
|
||||
isDashboard,
|
||||
documents,
|
||||
total,
|
||||
stats,
|
||||
incompleteDocs,
|
||||
recentDocs,
|
||||
@@ -87,7 +96,7 @@ export async function load({ url, fetch }) {
|
||||
senderName: senderObj ? `${senderObj.firstName} ${senderObj.lastName}` : '',
|
||||
receiverName: receiverObj ? `${receiverObj.firstName} ${receiverObj.lastName}` : ''
|
||||
},
|
||||
filters: { q, from, to, senderId, receiverId, tags },
|
||||
filters: { q, from, to, senderId, receiverId, tags, sort, dir, tagQ },
|
||||
error: null as string | null
|
||||
};
|
||||
} catch (e) {
|
||||
@@ -96,11 +105,12 @@ export async function load({ url, fetch }) {
|
||||
return {
|
||||
isDashboard,
|
||||
documents: [],
|
||||
total: 0,
|
||||
stats: null,
|
||||
incompleteDocs: [],
|
||||
recentDocs: [],
|
||||
initialValues: { senderName: '', receiverName: '' },
|
||||
filters: { q, from, to, senderId, receiverId, tags },
|
||||
filters: { q, from, to, senderId, receiverId, tags, sort, dir, tagQ },
|
||||
error: 'Daten konnten nicht geladen werden.' as string | null
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user