From c139faf47bc7f95570f8ba679b246ab7ef82646d Mon Sep 17 00:00:00 2001 From: Alexander Cai Date: Sun, 2 Jul 2023 12:36:25 -0400 Subject: [PATCH] if try to add duplicate event, skip instead of throw --- src/core/EventCache.ts | 16 +++++++++------- src/core/EventStore.ts | 4 ++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/core/EventCache.ts b/src/core/EventCache.ts index 4178c760..bdc168ce 100644 --- a/src/core/EventCache.ts +++ b/src/core/EventCache.ts @@ -567,14 +567,16 @@ export default class EventCache { location, calendarId: calendar.id, })); - newEvents.forEach(({ event, id, location }) => { - this.store.add({ - calendar, - location, - id, - event, + newEvents + .filter(({ id }) => !this.store.has(id)) + .forEach(({ event, id, location }) => { + this.store.add({ + calendar, + location, + id, + event, + }); }); - }); this.updateCalendar({ id: calendar.id, editable: false, diff --git a/src/core/EventStore.ts b/src/core/EventStore.ts index 405d83bb..49bbfe84 100644 --- a/src/core/EventStore.ts +++ b/src/core/EventStore.ts @@ -192,6 +192,10 @@ export default class EventStore { return result; } + has(id: string): boolean { + return this.store.has(id); + } + /** * Add a new event to the store with given associations. * @param param0