forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotificationDropdown.tsx
More file actions
72 lines (68 loc) · 2.22 KB
/
Copy pathNotificationDropdown.tsx
File metadata and controls
72 lines (68 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { Link } from "react-router-dom";
import { useNotificationsStore } from "../../store/notifications";
import { NotificationItem } from "./NotificationItem";
interface NotificationDropdownProps {
onClose?: () => void;
maxItems?: number;
}
export function NotificationDropdown({
onClose,
maxItems = 5,
}: NotificationDropdownProps) {
const notifications = useNotificationsStore((state) => state.notifications);
const unreadCount = useNotificationsStore((state) =>
state.notifications.filter((n) => !n.read).length
);
const markAllAsRead = useNotificationsStore((state) => state.markAllAsRead);
const displayList = notifications.slice(0, maxItems);
const hasMore = notifications.length > maxItems;
const handleMarkAllRead = () => {
markAllAsRead();
onClose?.();
};
return (
<div
role="dialog"
aria-label="Notifications"
className="absolute right-0 top-full mt-2 w-[min(90vw,380px)] rounded-xl border border-theme bg-card-theme shadow-lg z-50 flex flex-col max-h-[80vh]"
data-testid="notification-dropdown"
>
<div className="flex items-center justify-between px-4 py-3 border-b border-theme">
<h3 className="text-sm font-semibold text-theme">Notifications</h3>
{unreadCount > 0 && (
<button
type="button"
onClick={handleMarkAllRead}
className="text-xs text-accent hover:underline"
>
Mark all as read
</button>
)}
</div>
<div className="overflow-y-auto overscroll-contain">
{displayList.length === 0 ? (
<p className="p-4 text-sm text-muted-theme text-center">
No notifications yet.
</p>
) : (
<ul className="divide-y divide-theme">
{displayList.map((n) => (
<li key={n.id}>
<NotificationItem notification={n} compact />
</li>
))}
</ul>
)}
</div>
{hasMore && (
<Link
to="/notifications"
onClick={onClose}
className="block py-2 text-center text-sm text-accent hover:underline border-t border-theme"
>
View all notifications
</Link>
)}
</div>
);
}