From 9d2990a23b60d139f8774b41d7f89f146c7cf114 Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 8 Sep 2022 00:25:10 +0200 Subject: [PATCH] feat: allow saving a default reminder amount --- src/helpers/defaultReminder.ts | 42 ++++++++++++++++++++++ src/i18n/lang/en.json | 6 +++- src/modelTypes/IUserSettings.ts | 2 ++ src/models/userSettings.ts | 2 ++ src/styles/theme/form.scss | 4 +++ src/views/user/settings/General.vue | 54 +++++++++++++++++++++++++++++ 6 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 src/helpers/defaultReminder.ts diff --git a/src/helpers/defaultReminder.ts b/src/helpers/defaultReminder.ts new file mode 100644 index 00000000..53b389b1 --- /dev/null +++ b/src/helpers/defaultReminder.ts @@ -0,0 +1,42 @@ +const DEFAULT_REMINDER_KEY = 'defaultReminder' + +interface DefaultReminderSettings { + enabled: boolean, + amount: number, +} + +function calculateDefaultReminderSeconds(type: string, amount: number): number { + switch (type) { + case 'minutes': + return amount * 60 + case 'hours': + return amount * 60 * 60 + case 'days': + return amount * 60 * 60 * 24 + case 'months': + return amount * 60 * 60 * 24 * 30 + } + + return 0 +} + +export function saveDefaultReminder(enabled: boolean, type: string, amount: number) { + const defaultReminderSeconds = calculateDefaultReminderSeconds(type, amount) + localStorage.setItem(DEFAULT_REMINDER_KEY, JSON.stringify({ + enabled, + amount: defaultReminderSeconds, + })) +} + +export function getDefaultReminderAmount(): number | null { + const s: string | null = localStorage.getItem(DEFAULT_REMINDER_KEY) + if (s === null) { + return null + } + + const settings: DefaultReminderSettings = JSON.parse(s) + + return settings.enabled + ? settings.amount + : null +} diff --git a/src/i18n/lang/en.json b/src/i18n/lang/en.json index 4674f6e8..4b1fc8f2 100644 --- a/src/i18n/lang/en.json +++ b/src/i18n/lang/en.json @@ -87,7 +87,11 @@ "language": "Language", "defaultList": "Default List", "timezone": "Time Zone", - "overdueTasksRemindersTime": "Overdue tasks reminder email time" + "overdueTasksRemindersTime": "Overdue tasks reminder email time", + "defaultReminder": "Set a default task reminder", + "defaultReminderHint": "If enabled, Vikunja will automatically create a reminder for a task if you set a due date and the task does not have any reminders yet.", + "defaultReminderAmount": "Default task reminder amount", + "defaultReminderAmountHint": "The time difference the reminder will be set to before the due date." }, "totp": { "title": "Two Factor Authentication", diff --git a/src/modelTypes/IUserSettings.ts b/src/modelTypes/IUserSettings.ts index 31e921e0..9ba54a55 100644 --- a/src/modelTypes/IUserSettings.ts +++ b/src/modelTypes/IUserSettings.ts @@ -12,4 +12,6 @@ export interface IUserSettings extends IAbstract { weekStart: 0 | 1 | 2 | 3 | 4 | 5 | 6 timezone: string language: string + defaultReminder: boolean + defaultReminderAmount: number // The amount of seconds a reminder should be set before a given due date } \ No newline at end of file diff --git a/src/models/userSettings.ts b/src/models/userSettings.ts index ddb6f029..fbe02b73 100644 --- a/src/models/userSettings.ts +++ b/src/models/userSettings.ts @@ -13,6 +13,8 @@ export default class UserSettingsModel extends AbstractModel impl weekStart = 0 as IUserSettings['weekStart'] timezone = '' language = getCurrentLanguage() + defaultReminder = false + defaultReminderAmount = 0 constructor(data: Partial = {}) { super() diff --git a/src/styles/theme/form.scss b/src/styles/theme/form.scss index 86c78f2f..7ac5aa23 100644 --- a/src/styles/theme/form.scss +++ b/src/styles/theme/form.scss @@ -56,6 +56,10 @@ } } +.field.has-addons .select select { + height: 100%; +} + .field.has-addons .control .select select { height: 100%; } diff --git a/src/views/user/settings/General.vue b/src/views/user/settings/General.vue index 2664fe01..3ab31ccf 100644 --- a/src/views/user/settings/General.vue +++ b/src/views/user/settings/General.vue @@ -18,6 +18,55 @@ +
+ +

+ {{ $t('user.settings.general.defaultReminderHint') }} +

+
+
+ +

+ {{ $t('user.settings.general.defaultReminderAmountHint') }} +

+
+ +
+ +
+
+ +
+
+