MOBILE-3909 calendar: Fix default reminder duplicated when editing

main
Dani Palou 2022-03-15 15:25:07 +01:00
parent 1db5b85e40
commit c0b170b5f0
2 changed files with 5 additions and 4 deletions

View File

@ -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<void> {
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;
}

View File

@ -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))),
);