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.

Signed-off-by: Matteo Settenvini <matteo@member.fsf.org>
This commit is contained in:
Matteo Settenvini 2021-03-31 20:53:33 +02:00 committed by Matteo Settenvini
parent bea17a7109
commit 9e6b1c7536
1 changed files with 14 additions and 0 deletions

View File

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