refactor Notifications agenda

This commit is contained in:
alma 2026-01-16 02:52:17 +01:00
parent f23fd45c4c
commit 5c9a179c5a
2 changed files with 16 additions and 7 deletions

View File

@ -144,11 +144,12 @@ export function CalendarWidget() {
setEvents(upcomingEvents.slice(0, 5)); // Keep only 5 for display
// 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 => ({
id: evt.id,
title: evt.title,
start: evt.start,
end: evt.end,
start: evt.start instanceof Date ? evt.start : new Date(evt.start),
end: evt.end instanceof Date ? evt.end : new Date(evt.end),
isAllDay: evt.isAllDay,
calendarName: evt.calendarName,
calendarColor: evt.calendarColor,
@ -160,14 +161,20 @@ export function CalendarWidget() {
id: e.id,
title: e.title,
start: e.start instanceof Date ? e.start.toISOString() : e.start,
isAllDay: e.isAllDay,
})),
});
window.dispatchEvent(new CustomEvent('calendar-events-updated', {
detail: {
events: eventsForNotification,
}
}));
try {
window.dispatchEvent(new CustomEvent('calendar-events-updated', {
detail: {
events: eventsForNotification,
}
}));
console.log('[Calendar Widget] ✅ Event dispatched successfully');
} catch (error) {
console.error('[Calendar Widget] ❌ Error dispatching event', error);
}
setError(null);
} catch (err) {

View File

@ -25,6 +25,8 @@ export function useCalendarEventNotifications() {
const checkIntervalRef = useRef<NodeJS.Timeout | null>(null);
useEffect(() => {
console.log('[useCalendarEventNotifications] 🎧 Hook initialized, listening for calendar-events-updated');
// Listen for calendar events updates
const handleEventsUpdate = (event: CustomEvent) => {
const events = event.detail?.events || [];