fix: prevent crash when deleting calendar
- Add safety check for calendar.events access to prevent undefined error - Auto-remove deleted calendars from selectedCalendars state - Fixes TypeError: Cannot read properties of undefined (reading 'events')
This commit is contained in:
committed by
Benoit TELLIER
parent
f278caf041
commit
58977af1b1
@@ -79,9 +79,11 @@ export default function CalendarApp({
|
||||
const pending = useAppSelector((state) => state.calendars.pending);
|
||||
const [selectedCalendars, setSelectedCalendars] = useState<string[]>([]);
|
||||
|
||||
const dottedEvents: CalendarEvent[] = selectedCalendars.flatMap((calId) =>
|
||||
Object.values(calendars[calId].events)
|
||||
);
|
||||
const dottedEvents: CalendarEvent[] = selectedCalendars.flatMap((calId) => {
|
||||
const calendar = calendars[calId];
|
||||
if (!calendar?.events) return [];
|
||||
return Object.values(calendar.events);
|
||||
});
|
||||
|
||||
const [currentView, setCurrentView] = useState("timeGridWeek");
|
||||
const timezone = useAppSelector((state) => state.calendars.timeZone);
|
||||
@@ -114,6 +116,13 @@ export default function CalendarApp({
|
||||
}
|
||||
}, [calendars, userId]);
|
||||
|
||||
useEffect(() => {
|
||||
const validCalendarIds = new Set(Object.keys(calendars));
|
||||
setSelectedCalendars((prev) =>
|
||||
prev.filter((calId) => validCalendarIds.has(calId))
|
||||
);
|
||||
}, [calendars]);
|
||||
|
||||
const calendarRange = getCalendarRange(selectedDate);
|
||||
|
||||
// Create a stable string key for the range
|
||||
|
||||
Reference in New Issue
Block a user