make website run
This commit is contained in:
@@ -4,10 +4,6 @@ import React, { useState, useEffect, useRef } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import Link from 'next/link';
|
||||
import { useEffectiveDriverId } from '@/lib/currentDriver';
|
||||
import {
|
||||
getNotificationRepository,
|
||||
getMarkNotificationReadUseCase,
|
||||
} from '@/lib/di-container';
|
||||
import type { Notification } from '@core/notifications/application';
|
||||
import {
|
||||
Bell,
|
||||
@@ -52,23 +48,24 @@ export default function NotificationCenter() {
|
||||
const currentDriverId = useEffectiveDriverId();
|
||||
|
||||
// Polling for new notifications
|
||||
useEffect(() => {
|
||||
const loadNotifications = async () => {
|
||||
try {
|
||||
const repo = getNotificationRepository();
|
||||
const allNotifications = await repo.findByRecipientId(currentDriverId);
|
||||
setNotifications(allNotifications);
|
||||
} catch (error) {
|
||||
console.error('Failed to load notifications:', error);
|
||||
}
|
||||
};
|
||||
// TODO
|
||||
// useEffect(() => {
|
||||
// const loadNotifications = async () => {
|
||||
// try {
|
||||
// const repo = getNotificationRepository();
|
||||
// const allNotifications = await repo.findByRecipientId(currentDriverId);
|
||||
// setNotifications(allNotifications);
|
||||
// } catch (error) {
|
||||
// console.error('Failed to load notifications:', error);
|
||||
// }
|
||||
// };
|
||||
|
||||
loadNotifications();
|
||||
// loadNotifications();
|
||||
|
||||
// Poll every 5 seconds
|
||||
const interval = setInterval(loadNotifications, 5000);
|
||||
return () => clearInterval(interval);
|
||||
}, [currentDriverId]);
|
||||
// // Poll every 5 seconds
|
||||
// const interval = setInterval(loadNotifications, 5000);
|
||||
// return () => clearInterval(interval);
|
||||
// }, [currentDriverId]);
|
||||
|
||||
// Close panel when clicking outside
|
||||
useEffect(() => {
|
||||
|
||||
@@ -2,10 +2,7 @@
|
||||
|
||||
import { createContext, useContext, useState, useEffect, useCallback, ReactNode } from 'react';
|
||||
import { useEffectiveDriverId } from '@/lib/currentDriver';
|
||||
import {
|
||||
getNotificationRepository,
|
||||
getMarkNotificationReadUseCase,
|
||||
} from '@/lib/di-container';
|
||||
|
||||
import type { Notification } from '@core/notifications/application';
|
||||
import ToastNotification from './ToastNotification';
|
||||
import ModalNotification from './ModalNotification';
|
||||
@@ -44,45 +41,46 @@ export default function NotificationProvider({ children }: NotificationProviderP
|
||||
const currentDriverId = useEffectiveDriverId();
|
||||
|
||||
// Poll for new notifications
|
||||
useEffect(() => {
|
||||
const loadNotifications = async () => {
|
||||
try {
|
||||
const repo = getNotificationRepository();
|
||||
const allNotifications = await repo.findByRecipientId(currentDriverId);
|
||||
setNotifications(allNotifications);
|
||||
// TODO
|
||||
// useEffect(() => {
|
||||
// const loadNotifications = async () => {
|
||||
// try {
|
||||
// const repo = getNotificationRepository();
|
||||
// const allNotifications = await repo.findByRecipientId(currentDriverId);
|
||||
// setNotifications(allNotifications);
|
||||
|
||||
// Check for new notifications that need toast/modal display
|
||||
allNotifications.forEach((notification) => {
|
||||
// Check both unread and action_required status for modals
|
||||
const shouldDisplay = (notification.isUnread() || notification.isActionRequired()) &&
|
||||
!seenNotificationIds.has(notification.id);
|
||||
// // Check for new notifications that need toast/modal display
|
||||
// allNotifications.forEach((notification) => {
|
||||
// // Check both unread and action_required status for modals
|
||||
// const shouldDisplay = (notification.isUnread() || notification.isActionRequired()) &&
|
||||
// !seenNotificationIds.has(notification.id);
|
||||
|
||||
if (shouldDisplay) {
|
||||
// Mark as seen to prevent duplicate displays
|
||||
setSeenNotificationIds((prev) => new Set([...prev, notification.id]));
|
||||
// if (shouldDisplay) {
|
||||
// // Mark as seen to prevent duplicate displays
|
||||
// setSeenNotificationIds((prev) => new Set([...prev, notification.id]));
|
||||
|
||||
// Handle based on urgency
|
||||
if (notification.isModal()) {
|
||||
// Modal takes priority - show immediately
|
||||
setModalNotification(notification);
|
||||
} else if (notification.isToast()) {
|
||||
// Add to toast queue
|
||||
setToastNotifications((prev) => [...prev, notification]);
|
||||
}
|
||||
// Silent notifications just appear in the notification center
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Failed to load notifications:', error);
|
||||
}
|
||||
};
|
||||
// // Handle based on urgency
|
||||
// if (notification.isModal()) {
|
||||
// // Modal takes priority - show immediately
|
||||
// setModalNotification(notification);
|
||||
// } else if (notification.isToast()) {
|
||||
// // Add to toast queue
|
||||
// setToastNotifications((prev) => [...prev, notification]);
|
||||
// }
|
||||
// // Silent notifications just appear in the notification center
|
||||
// }
|
||||
// });
|
||||
// } catch (error) {
|
||||
// console.error('Failed to load notifications:', error);
|
||||
// }
|
||||
// };
|
||||
|
||||
loadNotifications();
|
||||
// loadNotifications();
|
||||
|
||||
// Poll every 2 seconds for responsiveness
|
||||
const interval = setInterval(loadNotifications, 2000);
|
||||
return () => clearInterval(interval);
|
||||
}, [currentDriverId, seenNotificationIds]);
|
||||
// // Poll every 2 seconds for responsiveness
|
||||
// const interval = setInterval(loadNotifications, 2000);
|
||||
// return () => clearInterval(interval);
|
||||
// }, [currentDriverId, seenNotificationIds]);
|
||||
|
||||
// Prevent body scroll when modal is open
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user