feat: notifications modal, admin dedup, and in-app notification preferences
All checks were successful
Release / Test backend (push) Successful in 48s
Release / Check ui (push) Successful in 1m53s
Release / Docker (push) Successful in 6m22s
Release / Gitea Release (push) Successful in 35s

- 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)
This commit is contained in:
root
2026-04-11 15:31:37 +05:00
parent 19b5b44454
commit 1e886a705d
10 changed files with 549 additions and 95 deletions

View File

@@ -1,8 +1,43 @@
import { json, error } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { deleteUserAccount } from '$lib/server/pocketbase';
import { deleteUserAccount, updateUserNotificationPrefs } from '$lib/server/pocketbase';
import { log } from '$lib/server/logger';
/**
* PATCH /api/profile
*
* Update mutable profile preferences (currently: notification preferences).
* Body: { notify_new_chapters?: boolean }
*/
export const PATCH: RequestHandler = async ({ locals, request }) => {
if (!locals.user) error(401, 'Not authenticated');
let body: Record<string, unknown>;
try {
body = await request.json();
} catch {
error(400, 'Invalid JSON');
}
const prefs: { notify_new_chapters?: boolean } = {};
if (typeof body.notify_new_chapters === 'boolean') {
prefs.notify_new_chapters = body.notify_new_chapters;
}
if (Object.keys(prefs).length === 0) {
error(400, 'No valid preferences provided');
}
try {
await updateUserNotificationPrefs(locals.user.id, prefs);
} catch (e) {
log.error('profile', 'PATCH /api/profile failed', { userId: locals.user.id, err: String(e) });
error(500, { message: 'Failed to update preferences. Please try again.' });
}
return json({ ok: true });
};
/**
* DELETE /api/profile
*