From 6bbd9b6484b61af90e2e46b8f8883670f0e2654a Mon Sep 17 00:00:00 2001 From: SaelixCode Date: Fri, 27 Feb 2026 12:47:16 -0500 Subject: [PATCH] feat: add notification deletion functionality in API and EditorLayout --- backend/src/index.ts | 19 ++++++++ backend/src/services/DatabaseService.ts | 10 ++++ frontend/src/components/EditorLayout.tsx | 58 +++++++++++++++++++----- 3 files changed, 75 insertions(+), 12 deletions(-) diff --git a/backend/src/index.ts b/backend/src/index.ts index 0c58665c..be8b7334 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -751,6 +751,25 @@ app.post('/api/notifications/read', async (req: Request, res: Response) => { } }); +app.delete('/api/notifications/:id', async (req: Request, res: Response) => { + try { + const id = parseInt(req.params.id as string, 10); + DatabaseService.getInstance().deleteNotification(id); + res.json({ success: true }); + } catch (error) { + res.status(500).json({ error: 'Failed to delete notification' }); + } +}); + +app.delete('/api/notifications', async (req: Request, res: Response) => { + try { + DatabaseService.getInstance().deleteAllNotifications(); + res.json({ success: true }); + } catch (error) { + res.status(500).json({ error: 'Failed to clear notifications' }); + } +}); + app.post('/api/notifications/test', async (req: Request, res: Response) => { try { const { type, url } = req.body; diff --git a/backend/src/services/DatabaseService.ts b/backend/src/services/DatabaseService.ts index 4208069a..006a2088 100644 --- a/backend/src/services/DatabaseService.ts +++ b/backend/src/services/DatabaseService.ts @@ -216,4 +216,14 @@ export class DatabaseService { const stmt = this.db.prepare('UPDATE notification_history SET is_read = 1'); stmt.run(); } + + public deleteNotification(id: number): void { + const stmt = this.db.prepare('DELETE FROM notification_history WHERE id = ?'); + stmt.run(id); + } + + public deleteAllNotifications(): void { + const stmt = this.db.prepare('DELETE FROM notification_history'); + stmt.run(); + } } diff --git a/frontend/src/components/EditorLayout.tsx b/frontend/src/components/EditorLayout.tsx index ffb43add..dbf0f164 100644 --- a/frontend/src/components/EditorLayout.tsx +++ b/frontend/src/components/EditorLayout.tsx @@ -160,6 +160,20 @@ export default function EditorLayout() { } catch (e) { } }; + const deleteNotification = async (id: number) => { + try { + await apiFetch(`/notifications/${id}`, { method: 'DELETE' }); + fetchNotifications(); + } catch (e) { } + }; + + const clearAllNotifications = async () => { + try { + await apiFetch('/notifications', { method: 'DELETE' }); + fetchNotifications(); + } catch (e) { } + }; + useEffect(() => { const wsMap: Record = {}; (containers || []).forEach(container => { @@ -725,11 +739,19 @@ export default function EditorLayout() {

Notifications

- {notifications.filter(n => !n.is_read).length > 0 && ( - - )} +
+ {notifications.filter(n => !n.is_read).length > 0 && ( + + )} + {notifications.length > 0 && ( + + )} +
{notifications.length === 0 ? ( @@ -737,8 +759,8 @@ export default function EditorLayout() { ) : (
{notifications.map((notif: any) => ( -
-
+
+
{notif.level} @@ -746,7 +768,20 @@ export default function EditorLayout() { {new Date(notif.timestamp).toLocaleString()}
-

{notif.message}

+

{notif.message}

+ + {/* Delete individual notification button */} +
))}
@@ -896,12 +931,11 @@ export default function EditorLayout() { Open App ({mainPort})