forked from codeaashu/claude-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseNotifications.ts
More file actions
54 lines (47 loc) · 1.5 KB
/
Copy pathuseNotifications.ts
File metadata and controls
54 lines (47 loc) · 1.5 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
"use client";
import { useCallback } from "react";
import { useNotificationStore, type NotificationCategory } from "@/lib/notifications";
import { browserNotifications } from "@/lib/browser-notifications";
export interface NotifyOptions {
title: string;
description: string;
category: NotificationCategory;
link?: string;
browserNotification?: boolean;
}
export function useNotifications() {
const notifications = useNotificationStore((s) => s.notifications);
const browserNotificationsEnabled = useNotificationStore(
(s) => s.browserNotificationsEnabled
);
const addNotification = useNotificationStore((s) => s.addNotification);
const markRead = useNotificationStore((s) => s.markRead);
const markAllRead = useNotificationStore((s) => s.markAllRead);
const clearHistory = useNotificationStore((s) => s.clearHistory);
const notify = useCallback(
async (options: NotifyOptions) => {
addNotification({
title: options.title,
description: options.description,
category: options.category,
link: options.link,
});
if (options.browserNotification && browserNotificationsEnabled) {
await browserNotifications.send({
title: options.title,
body: options.description,
});
}
},
[addNotification, browserNotificationsEnabled]
);
const unreadCount = notifications.filter((n) => !n.read).length;
return {
notifications,
unreadCount,
notify,
markRead,
markAllRead,
clearHistory,
};
}