From 5c9f68b08022773a0f175f0422f94f79f8969c56 Mon Sep 17 00:00:00 2001 From: alma Date: Sun, 4 May 2025 12:06:35 +0200 Subject: [PATCH] notifications --- app/notifications/page.tsx | 186 ------------------------------ components/notification-badge.tsx | 16 +-- 2 files changed, 3 insertions(+), 199 deletions(-) delete mode 100644 app/notifications/page.tsx diff --git a/app/notifications/page.tsx b/app/notifications/page.tsx deleted file mode 100644 index d6084b2b..00000000 --- a/app/notifications/page.tsx +++ /dev/null @@ -1,186 +0,0 @@ -"use client"; - -import { useEffect, useState } from 'react'; -import { useNotifications } from '@/hooks/use-notifications'; -import { Button } from '@/components/ui/button'; -import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'; -import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; -import { Notification } from '@/lib/types/notification'; -import { Badge } from '@/components/ui/badge'; -import { formatDistanceToNow } from 'date-fns'; -import { Bell, Check, CheckCheck, ExternalLink, Trash2 } from 'lucide-react'; -import Link from 'next/link'; - -// Source icon mapping -const SourceIcons: Record = { - leantime:
L
, - nextcloud:
N
, - gitea:
G
, - dolibarr:
D
, - moodle:
M
, -}; - -export default function NotificationsPage() { - const { notifications, notificationCount, loading, error, fetchNotifications, markAsRead, markAllAsRead } = useNotifications(); - const [activeTab, setActiveTab] = useState('all'); - - // Filter notifications based on active tab - const filteredNotifications = activeTab === 'all' - ? notifications - : notifications.filter(notification => notification.source === activeTab); - - // Group notifications by source for counts - const sourceCounts = Object.entries(notificationCount.sources).map(([source, count]) => ({ - source, - count: count.total, - unread: count.unread - })); - - const handleMarkAsRead = async (notification: Notification) => { - if (!notification.isRead) { - await markAsRead(notification.id); - } - }; - - const handleMarkAllAsRead = async () => { - await markAllAsRead(); - }; - - return ( -
-
-
-

Notifications

-

- Manage your notifications from all connected services -

-
- -
- - -
- - - All - {notificationCount.unread > 0 && ( - - {notificationCount.unread} - - )} - - - {sourceCounts.map(({ source, unread }) => ( - - {source} - {unread > 0 && ( - - {unread} - - )} - - ))} - -
- - - {loading ? ( - - -
-
-

Loading notifications...

-
-
-
- ) : error ? ( - - -
-

{error}

- -
-
-
- ) : filteredNotifications.length === 0 ? ( - - -
- -

No notifications

-

- You don't have any {activeTab !== 'all' ? `${activeTab} ` : ''}notifications right now. -

-
-
-
- ) : ( - filteredNotifications.map((notification) => ( - - -
-
- {SourceIcons[notification.source] || } -
-
-
-
-

- {notification.title} - {!notification.isRead && ( - New - )} -

-

- From {notification.source} • {formatDistanceToNow(new Date(notification.timestamp), { addSuffix: true })} -

-
-
- {!notification.isRead && ( - - )} - {notification.link && ( - - - - )} -
-
-

{notification.message}

-
-
-
-
- )) - )} -
-
-
- ); -} - diff --git a/components/notification-badge.tsx b/components/notification-badge.tsx index 5dd95401..84bef93e 100644 --- a/components/notification-badge.tsx +++ b/components/notification-badge.tsx @@ -34,8 +34,8 @@ export const NotificationBadge = memo(function NotificationBadge({ className }: setIsOpen(false); }; - // Take the latest 5 notifications for the dropdown - const recentNotifications = notifications.slice(0, 5); + // Take the latest 10 notifications for the dropdown + const recentNotifications = notifications.slice(0, 10); return (
@@ -55,7 +55,7 @@ export const NotificationBadge = memo(function NotificationBadge({ className }: Notifications - +

Notifications

{notificationCount.unread > 0 && ( @@ -116,16 +116,6 @@ export const NotificationBadge = memo(function NotificationBadge({ className }: ))} )} - - -
- - View all notifications - -