From 80cc58a45dc6bd125288294cba3bfc42e1cde45d Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 8 Sep 2022 16:38:12 +0200 Subject: [PATCH] feat: automatically add a reminder to a task with due date but no reminders --- src/services/task.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/services/task.ts b/src/services/task.ts index bb41b685..f0f098ed 100644 --- a/src/services/task.ts +++ b/src/services/task.ts @@ -6,6 +6,7 @@ import LabelService from './label' import {formatISO} from 'date-fns' import {colorFromHex} from '@/helpers/color/colorFromHex' +import {getDefaultReminderAmount} from '@/helpers/defaultReminder' const parseDate = date => { if (date) { @@ -39,7 +40,7 @@ export default class TaskService extends AbstractService { } processModel(updatedModel) { - const model = { ...updatedModel } + const model = {...updatedModel} model.title = model.title?.trim() @@ -68,6 +69,15 @@ export default class TaskService extends AbstractService { }) } + if (model.dueDate !== null && model.reminderDates.length === 0) { + const defaultReminder = getDefaultReminderAmount() + if (defaultReminder !== null) { + const dueDate = +new Date(model.dueDate) + const reminderDate = new Date(dueDate - (defaultReminder * 1000)) + model.reminderDates.push(formatISO(reminderDate)) + } + } + // Make the repeating amount to seconds let repeatAfterSeconds = 0 if (model.repeatAfter !== null && (model.repeatAfter.amount !== null || model.repeatAfter.amount !== 0)) {