From c0b170b5f01eb76b724d9d4b1e3cca22f3e2a65a Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 15 Mar 2022 15:25:07 +0100 Subject: [PATCH] MOBILE-3909 calendar: Fix default reminder duplicated when editing --- src/addons/calendar/pages/edit-event/edit-event.page.ts | 5 +++-- src/addons/calendar/services/calendar.ts | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/addons/calendar/pages/edit-event/edit-event.page.ts b/src/addons/calendar/pages/edit-event/edit-event.page.ts index d7bcfd094..c1807d35f 100644 --- a/src/addons/calendar/pages/edit-event/edit-event.page.ts +++ b/src/addons/calendar/pages/edit-event/edit-event.page.ts @@ -520,7 +520,7 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave { try { const result = await AddonCalendar.submitEvent(this.eventId, data, { - reminders: this.reminders, + reminders: this.eventId ? [] : this.reminders, // Only allow adding reminders for new events. }); event = result.event; @@ -638,7 +638,8 @@ export class AddonCalendarEditEventPage implements OnInit, OnDestroy, CanLeave { * @return Promise resolved when done. */ protected async initReminders(): Promise { - if (!this.notificationsEnabled) { + // Don't init reminders when editing an event. Right now, only allow adding reminders for new events. + if (!this.notificationsEnabled || this.eventId) { return; } diff --git a/src/addons/calendar/services/calendar.ts b/src/addons/calendar/services/calendar.ts index ec8c8db11..817b44ee1 100644 --- a/src/addons/calendar/services/calendar.ts +++ b/src/addons/calendar/services/calendar.ts @@ -1696,7 +1696,7 @@ export class AddonCalendarProvider { const event = await AddonCalendarOffline.saveEvent(eventId, formData, siteId); // Now save the reminders if any. - if (options.reminders) { + if (options.reminders?.length) { await CoreUtils.ignoreErrors( Promise.all(options.reminders.map((reminder) => this.addEventReminder(event, reminder.time, siteId))), ); @@ -1718,7 +1718,7 @@ export class AddonCalendarProvider { const event = await this.submitEventOnline(eventId, formData, siteId); // Now save the reminders if any. - if (options.reminders) { + if (options.reminders?.length) { await CoreUtils.ignoreErrors( Promise.all(options.reminders.map((reminder) => this.addEventReminder(event, reminder.time, siteId))), );