|
|
@@ -36,6 +36,18 @@ const NotificationContext = createContext<NotificationContextType | undefined>(
|
|
|
export function NotificationProvider({ children }: { children: ReactNode }) {
|
|
|
const [notifications, setNotifications] = useState<Notification[]>([]);
|
|
|
|
|
|
+ const addNotification = (
|
|
|
+ notification: Omit<Notification, "id" | "timestamp" | "read">
|
|
|
+ ) => {
|
|
|
+ const newNotification: Notification = {
|
|
|
+ ...notification,
|
|
|
+ id: Date.now().toString() + Math.random().toString(36).substr(2, 9),
|
|
|
+ timestamp: new Date(),
|
|
|
+ read: false
|
|
|
+ };
|
|
|
+ setNotifications((prev) => [newNotification, ...prev]);
|
|
|
+ };
|
|
|
+
|
|
|
// Listen for WebSocket events and add notifications
|
|
|
useEffect(() => {
|
|
|
const handleFileUpdate = (event: CustomEvent) => {
|
|
|
@@ -85,19 +97,7 @@ export function NotificationProvider({ children }: { children: ReactNode }) {
|
|
|
handleTaskUpdate as EventListener
|
|
|
);
|
|
|
};
|
|
|
- }, []);
|
|
|
-
|
|
|
- const addNotification = (
|
|
|
- notification: Omit<Notification, "id" | "timestamp" | "read">
|
|
|
- ) => {
|
|
|
- const newNotification: Notification = {
|
|
|
- ...notification,
|
|
|
- id: Date.now().toString() + Math.random().toString(36).substr(2, 9),
|
|
|
- timestamp: new Date(),
|
|
|
- read: false
|
|
|
- };
|
|
|
- setNotifications((prev) => [newNotification, ...prev]);
|
|
|
- };
|
|
|
+ }, [addNotification]);
|
|
|
|
|
|
const markAsRead = (id: string) => {
|
|
|
setNotifications((prev) =>
|