- Replace bell dropdown with full-screen NotificationsModal (mirrors SearchModal pattern) - Notifications visible to all logged-in users (not just admin) - Admin users excluded from new-chapter fan-out (dedup vs Scrape Complete notification) - Users with notify_new_chapters=false opted out of new-chapter in-app notifications - Toggle in profile page to enable/disable in-app new-chapter notifications - PATCH /api/profile endpoint to save notification preferences - User-facing /notifications page (admin redirects to /admin/notifications)
29 lines
759 B
TypeScript
29 lines
759 B
TypeScript
import type { PageServerLoad } from './$types';
|
|
import { redirect } from '@sveltejs/kit';
|
|
import { backendFetch } from '$lib/server/scraper';
|
|
|
|
export const load: PageServerLoad = async ({ locals }) => {
|
|
// Admins have their own full notifications page
|
|
if (locals.user?.role === 'admin') {
|
|
redirect(302, '/admin/notifications');
|
|
}
|
|
|
|
const userId = locals.user!.id;
|
|
try {
|
|
const res = await backendFetch('/api/notifications?user_id=' + userId);
|
|
const data = await res.json().catch(() => ({ notifications: [] }));
|
|
return {
|
|
userId,
|
|
notifications: (data.notifications ?? []) as Array<{
|
|
id: string;
|
|
title: string;
|
|
message: string;
|
|
link: string;
|
|
read: boolean;
|
|
}>
|
|
};
|
|
} catch {
|
|
return { userId, notifications: [] };
|
|
}
|
|
};
|