WIP: feat: add default reminder for tasks with a due date #2360

Draft
konrad wants to merge 17 commits from feature/add-default-reminder into main
2 changed files with 19 additions and 11 deletions
Showing only changes of commit 28312081ae - Show all commits

View File

@ -16,7 +16,7 @@ function calculateDefaultReminderSeconds(type: string, amount: number): number {
case 'months':
konrad marked this conversation as resolved Outdated

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.

Done.

Done.
return amount * 60 * 60 * 24 * 30
}
return 0
}
@ -29,14 +29,18 @@ export function saveDefaultReminder(enabled: boolean, type: string, amount: numb
}
export function getDefaultReminderAmount(): number | null {
const settings = getDefaultReminderSettings()
return settings?.enabled
? settings.amount
: null
}
export function getDefaultReminderSettings(): DefaultReminderSettings | null {
dpschen marked this conversation as resolved
Review

picky: don't create one-use-variable

picky: don't create one-use-variable
Review

But here I'm using it twice?

But here I'm using it twice?
Review

Beeing too picky is also stupid… you are right!

Beeing too picky is also stupid… you are right!
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
return JSON.parse(s)
}

View File

@ -20,14 +20,14 @@
</div>
<div class="field">
<label class="checkbox">
<input type="checkbox" v-model="settings.defaultReminder"/>
<input type="checkbox" v-model="defaultReminderEnabled"/>
{{ $t('user.settings.general.defaultReminder') }}
</label>
<p class="is-size-7">
{{ $t('user.settings.general.defaultReminderHint') }}
</p>
</div>
<div class="field" v-if="settings.defaultReminder">
<div class="field" v-if="defaultReminderEnabled">
<label class="label" for="defaultReminderAmount">
{{ $t('user.settings.general.defaultReminderAmount') }}
</label>
@ -219,7 +219,7 @@ import {AuthenticatedHTTPFactory} from '@/http-common'
import {useColorScheme} from '@/composables/useColorScheme'
import {useTitle} from '@/composables/useTitle'
import {objectIsEmpty} from '@/helpers/objectIsEmpty'
import {saveDefaultReminder} from '@/helpers/defaultReminder'
import {getDefaultReminderSettings, saveDefaultReminder} from '@/helpers/defaultReminder'
const {t} = useI18n({useScope: 'global'})
useTitle(() => `${t('user.settings.general.title')} - ${t('user.settings.title')}`)
@ -311,13 +311,17 @@ watch(
async function updateSettings() {
localStorage.setItem(playSoundWhenDoneKey, playSoundWhenDone.value ? 'true' : 'false')
setQuickAddMagicMode(quickAddMagicMode.value)
saveDefaultReminder(settings.value.defaultReminder, defaultReminderAmountType.value, defaultReminderAmount.value)
saveDefaultReminder(defaultReminderEnabled.value, defaultReminderAmountType.value, defaultReminderAmount.value)
await authStore.saveUserSettings({
settings: {...settings.value},
})
}
const reminderSettings = getDefaultReminderSettings()
const defaultReminderEnabled = ref<boolean>(reminderSettings?.enabled || false)
// TODO: re-populate amount and type
const defaultReminderAmount = ref(1)
konrad marked this conversation as resolved
Review

Shouldn't the fallback be the same as the default in the model?

Shouldn't the fallback be the same as the default in the model?
Review

Actually not, because this is what gets shown in the input when setting this for the first time. I felt like putting a 0 here would feel weired.

Actually not, because this is what gets shown in the input when setting this for the first time. I felt like putting a `0` here would feel weired.
const defaultReminderAmountType = ref('days')
</script>