From a145066c42bf45500e8bb725df19adc4b427fb4d Mon Sep 17 00:00:00 2001 From: Matteo Settenvini Date: Wed, 31 Mar 2021 20:53:33 +0200 Subject: [PATCH] Add user default reminder to new events Take the value from the saved settings for the default reminder, and if it is a valid amount of seconds, add a new alarm to newly created events. Fixes #629 Signed-off-by: Matteo Settenvini --- src/store/calendarObjectInstance.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/store/calendarObjectInstance.js b/src/store/calendarObjectInstance.js index 49ed0a81b6..fedfc768fb 100644 --- a/src/store/calendarObjectInstance.js +++ b/src/store/calendarObjectInstance.js @@ -45,6 +45,8 @@ import { } from '../utils/color.js' import { mapAlarmComponentToAlarmObject } from '../models/alarm.js' import { getObjectAtRecurrenceId } from '../utils/calendarObject.js' +import logger from '../utils/logger.js' +import settings from './settings.js' const state = { isNew: null, @@ -1430,6 +1432,18 @@ const actions = { const eventComponent = getObjectAtRecurrenceId(calendarObject, startDate) const calendarObjectInstance = mapEventComponentToEventObject(eventComponent) + // Add an alarm if the user set a default one in the settings. If + // not, defaultReminder will not be a number (rather the string "none"). + const defaultReminder = parseInt(settings.state.defaultReminder) + if (!isNaN(defaultReminder)) { + commit('addAlarmToCalendarObjectInstance', { + calendarObjectInstance: calendarObjectInstance, + type: 'DISPLAY', + totalSeconds: defaultReminder, + }) + logger.debug(`Added defaultReminder (${defaultReminder}s) to newly created event`) + } + commit('setCalendarObjectInstanceForNewEvent', { calendarObject, calendarObjectInstance,