feat(notifications): implement /notifications page with filter pills and load-more
New route with server load function (reads URL params, derives unreadCount from the page, single API call per Sara's architecture requirement), mark-all form action, and the full page UI: filter pills with ARIA radiogroup, notification rows with border+dot unread indicators (WCAG 1.4.1), "Ältere laden" client-side append, and empty state. Includes all de/en/es translation keys. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
35
frontend/src/routes/notifications/+page.server.ts
Normal file
35
frontend/src/routes/notifications/+page.server.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { error, redirect } from '@sveltejs/kit';
|
||||
import { createApiClient } from '$lib/api.server';
|
||||
import { getErrorMessage } from '$lib/errors';
|
||||
import type { PageServerLoad, Actions } from './$types';
|
||||
|
||||
export const load: PageServerLoad = async ({ fetch, url }) => {
|
||||
const api = createApiClient(fetch);
|
||||
|
||||
const type = url.searchParams.get('type') ?? undefined;
|
||||
const readParam = url.searchParams.get('read');
|
||||
const read = readParam !== null ? readParam === 'true' : undefined;
|
||||
|
||||
const result = await api.GET('/api/notifications', {
|
||||
params: { query: { type: type as 'MENTION' | 'REPLY' | undefined, read, page: 0, size: 20 } }
|
||||
});
|
||||
|
||||
if (!result.response.ok) {
|
||||
const code = (result.error as unknown as { code?: string })?.code;
|
||||
throw error(result.response.status, getErrorMessage(code));
|
||||
}
|
||||
|
||||
const page = result.data!;
|
||||
const notifications = page.content ?? [];
|
||||
const unreadCount = notifications.filter((n) => !n.read).length;
|
||||
|
||||
return { notifications, unreadCount, totalPages: page.totalPages ?? 1 };
|
||||
};
|
||||
|
||||
export const actions: Actions = {
|
||||
'mark-all': async ({ fetch }) => {
|
||||
const api = createApiClient(fetch);
|
||||
await api.POST('/api/notifications/read-all');
|
||||
redirect(303, '/notifications');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user