diff --git a/components/calendar/calendar-widget.tsx b/components/calendar/calendar-widget.tsx index 199c19d..a3ae9a7 100644 --- a/components/calendar/calendar-widget.tsx +++ b/components/calendar/calendar-widget.tsx @@ -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) { diff --git a/hooks/use-calendar-event-notifications.ts b/hooks/use-calendar-event-notifications.ts index 2e5ccb3..04d56ff 100644 --- a/hooks/use-calendar-event-notifications.ts +++ b/hooks/use-calendar-event-notifications.ts @@ -25,6 +25,8 @@ export function useCalendarEventNotifications() { const checkIntervalRef = useRef(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 || [];