feat: dedicated /documents search & browse page #282

Merged
marcel merged 50 commits from feat/issue-281-documents-page into main 2026-04-20 09:11:08 +02:00
2 changed files with 30 additions and 28 deletions
Showing only changes of commit da2ece986a - Show all commits

View File

@@ -97,7 +97,7 @@ function safeColor(color: string): string {
</div>
{#each resumeDoc.collaborators.slice(0, 3) as collab (collab.initials + collab.color)}
<span
class="-ml-1 inline-flex h-6 w-6 items-center justify-center rounded-full font-sans text-[10px] font-bold text-white ring-2 ring-white"
class="-ml-1 inline-flex h-6 w-6 items-center justify-center rounded-full font-sans text-xs font-bold text-white ring-2 ring-white"
style="background:{safeColor(collab.color)}">{collab.initials}</span
>
{/each}

View File

@@ -1,5 +1,6 @@
import { redirect } from '@sveltejs/kit';
import { createApiClient } from '$lib/api.server';
import { getErrorMessage } from '$lib/errors';
import type { components } from '$lib/generated/api';
type DocumentSearchItem = components['schemas']['DocumentSearchItem'];
@@ -29,8 +30,9 @@ export async function load({ url, fetch }) {
const api = createApiClient(fetch);
let result;
try {
const result = await api.GET('/api/documents/search', {
result = await api.GET('/api/documents/search', {
params: {
query: {
q: q || undefined,
@@ -46,32 +48,7 @@ export async function load({ url, fetch }) {
}
}
});
if (result.response.status === 401) {
throw redirect(302, '/login');
}
const items: DocumentSearchItem[] = (result.data?.items ?? []) as DocumentSearchItem[];
const total: number = result.data?.total ?? 0;
return {
items,
total,
q,
from,
to,
senderId,
receiverId,
tags,
sort,
dir,
tagQ,
tagOp,
error: null as string | null
};
} catch (e) {
if ((e as { status?: number }).status) throw e;
console.error('Error loading documents:', e);
} catch {
return {
items: [] as DocumentSearchItem[],
total: 0,
@@ -88,4 +65,29 @@ export async function load({ url, fetch }) {
error: 'Daten konnten nicht geladen werden.' as string | null
};
}
if (result.response.status === 401) {
throw redirect(302, '/login');
}
const errorMessage: string | null = !result.response.ok
? (getErrorMessage((result.error as unknown as { code?: string })?.code) ??
'Daten konnten nicht geladen werden.')
: null;
return {
items: (result.data?.items ?? []) as DocumentSearchItem[],
total: result.data?.total ?? 0,
q,
from,
to,
senderId,
receiverId,
tags,
sort,
dir,
tagQ,
tagOp,
error: errorMessage
};
}