wip
This commit is contained in:
@@ -18,6 +18,7 @@ interface NotificationContextValue {
|
||||
markAsRead: (notification: Notification) => Promise<void>;
|
||||
dismissToast: (notification: Notification) => void;
|
||||
respondToModal: (notification: Notification, actionId?: string) => Promise<void>;
|
||||
dismissModal: (notification: Notification) => Promise<void>;
|
||||
}
|
||||
|
||||
const NotificationContext = createContext<NotificationContextValue | null>(null);
|
||||
@@ -132,6 +133,25 @@ export default function NotificationProvider({ children }: NotificationProviderP
|
||||
}
|
||||
}, []);
|
||||
|
||||
const dismissModal = useCallback(async (notification: Notification) => {
|
||||
try {
|
||||
// Dismiss the notification
|
||||
const repo = getNotificationRepository();
|
||||
const updated = notification.dismiss();
|
||||
await repo.update(updated);
|
||||
|
||||
// Update local state
|
||||
setNotifications((prev) =>
|
||||
prev.map((n) => (n.id === notification.id ? updated : n))
|
||||
);
|
||||
|
||||
// Clear modal
|
||||
setModalNotification(null);
|
||||
} catch (error) {
|
||||
console.error('Failed to dismiss notification:', error);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const unreadCount = notifications.filter((n) => n.isUnread() || n.isActionRequired()).length;
|
||||
|
||||
const value: NotificationContextValue = {
|
||||
@@ -142,6 +162,7 @@ export default function NotificationProvider({ children }: NotificationProviderP
|
||||
markAsRead,
|
||||
dismissToast,
|
||||
respondToModal,
|
||||
dismissModal,
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -165,6 +186,7 @@ export default function NotificationProvider({ children }: NotificationProviderP
|
||||
<ModalNotification
|
||||
notification={modalNotification}
|
||||
onAction={respondToModal}
|
||||
onDismiss={dismissModal}
|
||||
/>
|
||||
)}
|
||||
</NotificationContext.Provider>
|
||||
|
||||
Reference in New Issue
Block a user