/**
* NotificationsContext
*
* Provides shared notification state across the entire application.
* This ensures the notification bell, notifications panel, and notifications page
* all share the same state, so updates in one place reflect everywhere.
*/
'use client';
import React, { createContext, useContext, ReactNode } from 'react';
import { useNotifications as useNotificationsHook, type Notification } from '@/hooks/useNotifications';
interface NotificationsContextType {
notifications: Notification[];
unreadCount: number;
loading: boolean;
fetchNotifications: (limit?: number, offset?: number) => Promise<void>;
fetchUnreadCount: () => Promise<void>;
markAsRead: (notificationIds?: string[]) => Promise<void>;
markOneAsRead: (notificationId: string) => void;
deleteNotification: (notificationId: string) => Promise<void>;
}
const NotificationsContext = createContext<NotificationsContextType | undefined>(undefined);
export function NotificationsProvider({ children }: { children: ReactNode }) {
const notificationsState = useNotificationsHook();
return (
<NotificationsContext.Provider value={notificationsState}>
{children}
</NotificationsContext.Provider>
);
}
export function useNotificationsContext() {
const context = useContext(NotificationsContext);
if (context === undefined) {
throw new Error('useNotificationsContext must be used within a NotificationsProvider');
}
return context;
}
// Re-export types for convenience
export type { Notification } from '@/hooks/useNotifications';