refactor Notifications agenda
This commit is contained in:
parent
f23fd45c4c
commit
5c9a179c5a
@ -144,11 +144,12 @@ export function CalendarWidget() {
|
|||||||
setEvents(upcomingEvents.slice(0, 5)); // Keep only 5 for display
|
setEvents(upcomingEvents.slice(0, 5)); // Keep only 5 for display
|
||||||
|
|
||||||
// Dispatch event for Outlook-style notifications (when events start)
|
// Dispatch event for Outlook-style notifications (when events start)
|
||||||
|
// Always dispatch, not just when count changes, so the hook can track events
|
||||||
const eventsForNotification = upcomingEvents.map(evt => ({
|
const eventsForNotification = upcomingEvents.map(evt => ({
|
||||||
id: evt.id,
|
id: evt.id,
|
||||||
title: evt.title,
|
title: evt.title,
|
||||||
start: evt.start,
|
start: evt.start instanceof Date ? evt.start : new Date(evt.start),
|
||||||
end: evt.end,
|
end: evt.end instanceof Date ? evt.end : new Date(evt.end),
|
||||||
isAllDay: evt.isAllDay,
|
isAllDay: evt.isAllDay,
|
||||||
calendarName: evt.calendarName,
|
calendarName: evt.calendarName,
|
||||||
calendarColor: evt.calendarColor,
|
calendarColor: evt.calendarColor,
|
||||||
@ -160,14 +161,20 @@ export function CalendarWidget() {
|
|||||||
id: e.id,
|
id: e.id,
|
||||||
title: e.title,
|
title: e.title,
|
||||||
start: e.start instanceof Date ? e.start.toISOString() : e.start,
|
start: e.start instanceof Date ? e.start.toISOString() : e.start,
|
||||||
|
isAllDay: e.isAllDay,
|
||||||
})),
|
})),
|
||||||
});
|
});
|
||||||
|
|
||||||
window.dispatchEvent(new CustomEvent('calendar-events-updated', {
|
try {
|
||||||
detail: {
|
window.dispatchEvent(new CustomEvent('calendar-events-updated', {
|
||||||
events: eventsForNotification,
|
detail: {
|
||||||
}
|
events: eventsForNotification,
|
||||||
}));
|
}
|
||||||
|
}));
|
||||||
|
console.log('[Calendar Widget] ✅ Event dispatched successfully');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[Calendar Widget] ❌ Error dispatching event', error);
|
||||||
|
}
|
||||||
|
|
||||||
setError(null);
|
setError(null);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@ -25,6 +25,8 @@ export function useCalendarEventNotifications() {
|
|||||||
const checkIntervalRef = useRef<NodeJS.Timeout | null>(null);
|
const checkIntervalRef = useRef<NodeJS.Timeout | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
console.log('[useCalendarEventNotifications] 🎧 Hook initialized, listening for calendar-events-updated');
|
||||||
|
|
||||||
// Listen for calendar events updates
|
// Listen for calendar events updates
|
||||||
const handleEventsUpdate = (event: CustomEvent) => {
|
const handleEventsUpdate = (event: CustomEvent) => {
|
||||||
const events = event.detail?.events || [];
|
const events = event.detail?.events || [];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user