Skip to content

Commit

Permalink
Add user default reminder to new events
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
tchernobog committed Mar 31, 2021
1 parent 1fc13e0 commit d680b11
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/store/calendarObjectInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d680b11

Please sign in to comment.