chore: better typing
continuous-integration/drone/pr Build is failing Details

This commit is contained in:
kolaente 2022-09-30 13:27:14 +02:00
parent d5bc1cd1d6
commit e623954351
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 7 additions and 8 deletions

View File

@ -1,10 +1,7 @@
const DEFAULT_REMINDER_KEY = 'defaultReminder' const DEFAULT_REMINDER_KEY = 'defaultReminder'
export const AMOUNTS_IN_SECONDS: { export const AMOUNTS_IN_SECONDS: {
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 {
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)
} }
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,
} }
} }