From 1b50d197b107aacb8bfdb4d4647ac83a5849ee13 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Wed, 11 Nov 2020 09:39:41 +0200 Subject: [PATCH] Calendar: gracefully handle errors handling recurring events. --- src/Calendars/Calendar.tsx | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Calendars/Calendar.tsx b/src/Calendars/Calendar.tsx index d78084f..2e7b4d3 100644 --- a/src/Calendars/Calendar.tsx +++ b/src/Calendars/Calendar.tsx @@ -6,6 +6,8 @@ import { Calendar as BigCalendar, momentLocalizer, View } from "react-big-calend import "react-big-calendar/lib/css/react-big-calendar.css"; import moment from "moment"; import * as ICAL from "ical.js"; +import { store } from "../store"; +import { appendError } from "../store/actions"; import { EventType } from "../pim-types"; @@ -55,21 +57,25 @@ class Calendar extends React.PureComponent { this.props.entries.forEach((event) => { entries.push(event); - if (event.isRecurring()) { - const recur = event.iterator(); - - let next = recur.next(); // Skip the first one - while ((next = recur.next())) { - if (next.compare(MAX_RECURRENCE_DATE) > 0) { - break; + try { + if (event.isRecurring()) { + const recur = event.iterator(); + + let next = recur.next(); // Skip the first one + while ((next = recur.next())) { + if (next.compare(MAX_RECURRENCE_DATE) > 0) { + break; + } + + const shift = next.subtractDateTz(event.startDate); + const ev = event.clone(); + ev.startDate.addDuration(shift); + ev.endDate.addDuration(shift); + entries.push(ev); } - - const shift = next.subtractDateTz(event.startDate); - const ev = event.clone(); - ev.startDate.addDuration(shift); - ev.endDate.addDuration(shift); - entries.push(ev); } + } catch (e) { + store.dispatch(appendError(e)); } });