WIP: feat: add default reminder for tasks with a due date #2360
|
@ -1,10 +1,7 @@
|
||||||
const DEFAULT_REMINDER_KEY = 'defaultReminder'
|
const DEFAULT_REMINDER_KEY = 'defaultReminder'
|
||||||
|
|
||||||
export const AMOUNTS_IN_SECONDS: {
|
export const AMOUNTS_IN_SECONDS: {
|
||||||
konrad marked this conversation as resolved
|
|||||||
minutes: number,
|
[type in SavedReminderSettings['type']]: number
|
||||||
hours: number,
|
|
||||||
days: number,
|
|
||||||
months: number,
|
|
||||||
} = {
|
} = {
|
||||||
minutes: 60,
|
minutes: 60,
|
||||||
hours: 60 * 60,
|
hours: 60 * 60,
|
||||||
|
@ -19,15 +16,15 @@ interface DefaultReminderSettings {
|
||||||
|
|
||||||
konrad marked this conversation as resolved
Outdated
dpschen
commented
We should save the factors in array in a mapping constant. This way the constant can be reused for the test. We should save the factors in array in a mapping constant. This way the constant can be reused for the test.
konrad
commented
Done. Done.
|
|||||||
interface SavedReminderSettings {
|
interface SavedReminderSettings {
|
||||||
enabled: boolean,
|
enabled: boolean,
|
||||||
amount?: number,
|
amount: number,
|
||||||
type?: 'minutes' | 'hours' | 'days' | 'months',
|
type: 'minutes' | 'hours' | 'days' | 'months',
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculateDefaultReminderSeconds(type: string, amount: number): number {
|
function calculateDefaultReminderSeconds(type: SavedReminderSettings['type'], amount: number): number {
|
||||||
return amount * (AMOUNTS_IN_SECONDS[type] || 0)
|
return amount * (AMOUNTS_IN_SECONDS[type] || 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
konrad marked this conversation as resolved
dpschen
commented
Maybe we should save the
`type` would better be as `keyof typeof AMOUNT_IN_SECONDS`.
Maybe we should save the `type` as new type, e.g.
```ts
type IReminderDurationType = 'minutes' | 'hours' | 'days' | 'months'
```
konrad
commented
I've changed it to use I've changed it to use `SavedReminderSettings['type']` instead.
|
|||||||
export function saveDefaultReminder(enabled: boolean, type: string, amount: number) {
|
export function saveDefaultReminder(enabled: boolean, type: SavedReminderSettings['type'], amount: number) {
|
||||||
const defaultReminderSeconds = calculateDefaultReminderSeconds(type, amount)
|
const defaultReminderSeconds = calculateDefaultReminderSeconds(type, amount)
|
||||||
localStorage.setItem(DEFAULT_REMINDER_KEY, JSON.stringify(<DefaultReminderSettings>{
|
localStorage.setItem(DEFAULT_REMINDER_KEY, JSON.stringify(<DefaultReminderSettings>{
|
||||||
enabled,
|
enabled,
|
||||||
|
@ -83,6 +80,8 @@ export function getSavedReminderSettings(): SavedReminderSettings | null {
|
||||||
if (!s.enabled) {
|
if (!s.enabled) {
|
||||||
return {
|
return {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
|
type: 'minutes',
|
||||||
|
amount: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user
Reuse type definition. E.g.
Done.