MCPcopy
hub / github.com/codeaashu/claude-code / useNotifications

Function useNotifications

src/context/notifications.tsx:38–229  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

36// Track current timeout to clear it when immediate notifications arrive
37let currentTimeoutId: NodeJS.Timeout | null = null;
38export function useNotifications(): {
39 addNotification: AddNotificationFn;
40 removeNotification: RemoveNotificationFn;
41} {
42 const store = useAppStateStore();
43 const setAppState = useSetAppState();
44
45 // Process queue when current notification finishes or queue changes
46 const processQueue = useCallback(() => {
47 setAppState(prev => {
48 const next = getNext(prev.notifications.queue);
49 if (prev.notifications.current !== null || !next) {
50 return prev;
51 }
52 currentTimeoutId = setTimeout((setAppState, nextKey, processQueue) => {
53 currentTimeoutId = null;
54 setAppState(prev => {
55 // Compare by key instead of reference to handle re-created notifications
56 if (prev.notifications.current?.key !== nextKey) {
57 return prev;
58 }
59 return {
60 ...prev,
61 notifications: {
62 queue: prev.notifications.queue,
63 current: null
64 }
65 };
66 });
67 processQueue();
68 }, next.timeoutMs ?? DEFAULT_TIMEOUT_MS, setAppState, next.key, processQueue);
69 return {
70 ...prev,
71 notifications: {
72 queue: prev.notifications.queue.filter(_ => _ !== next),
73 current: next
74 }
75 };
76 });
77 }, [setAppState]);
78 const addNotification = useCallback<AddNotificationFn>((notif: Notification) => {
79 // Handle immediate priority notifications
80 if (notif.priority === 'immediate') {
81 // Clear any existing timeout since we're showing a new immediate notification
82 if (currentTimeoutId) {
83 clearTimeout(currentTimeoutId);
84 currentTimeoutId = null;
85 }
86
87 // Set up timeout for the immediate notification
88 currentTimeoutId = setTimeout((setAppState, notif, processQueue) => {
89 currentTimeoutId = null;
90 setAppState(prev => {
91 // Compare by key instead of reference to handle re-created notifications
92 if (prev.notifications.current?.key !== notif.key) {
93 return prev;
94 }
95 return {

Callers 15

useKeybindingWarningsFunction · 0.50
StatusLineInnerFunction · 0.50
ScrollKeybindingHandlerFunction · 0.50
PromptInputFunction · 0.50
NotificationsFunction · 0.50
REPLFunction · 0.50
useBuddyNotificationFunction · 0.50
useManageMCPConnectionsFunction · 0.50
useArrowKeyHistoryFunction · 0.50
useReplBridgeFunction · 0.50

Calls 5

useAppStateStoreFunction · 0.85
useSetAppStateFunction · 0.85
getNextFunction · 0.85
processQueueFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected