|
| 1 | +<template> |
| 2 | + <div> |
| 3 | + <div class="settings-item"> |
| 4 | + <label class="setting-header"> |
| 5 | + <input |
| 6 | + type="checkbox" |
| 7 | + class="filled-in" |
| 8 | + id="blockDeferral" |
| 9 | + v-model="showDailyNotifacation" |
| 10 | + @change="onChange(StorageParams.DAILY_NOTIFICATION, $event.target)" |
| 11 | + /> |
| 12 | + <span>Daily Summary Notifications</span> |
| 13 | + <p class="description"> |
| 14 | + At the end of each day, you will receive a notification with a summary of your daily |
| 15 | + usage. |
| 16 | + </p> |
| 17 | + </label> |
| 18 | + </div> |
| 19 | + <div class="settings-item"> |
| 20 | + <p class="setting-header d-inline-block"> |
| 21 | + Notification time with summary information about your daily usage |
| 22 | + </p> |
| 23 | + <VueDatePicker |
| 24 | + v-model="notificationTime" |
| 25 | + time-picker |
| 26 | + @update:model-value="handleDate" |
| 27 | + class="date-picker d-inline-block" |
| 28 | + /> |
| 29 | + </div> |
| 30 | + </div> |
| 31 | +</template> |
| 32 | + |
| 33 | +<script lang="ts"> |
| 34 | +export default { |
| 35 | + name: 'DailyNotifications', |
| 36 | +}; |
| 37 | +</script> |
| 38 | + |
| 39 | +<script lang="ts" setup> |
| 40 | +import { onMounted, ref } from 'vue'; |
| 41 | +import { injecStorage } from '../storage/inject-storage'; |
| 42 | +import { StorageParams } from '../storage/storage-params'; |
| 43 | +import { |
| 44 | + DAILY_NOTIFICATION_DEFAULT, |
| 45 | + DAILY_SUMMARY_NOTIFICATION_TIME_DEFAULT, |
| 46 | +} from '../storage/storage-params'; |
| 47 | +import { convertHHMMToSeconds, convertSecondsToHHMM } from '../utils/converter'; |
| 48 | +import { Time } from '../utils/time'; |
| 49 | +
|
| 50 | +const settingsStorage = injecStorage(); |
| 51 | +
|
| 52 | +const showDailyNotifacation = ref<boolean>(); |
| 53 | +const dailyNotificationTime = ref<number>(); |
| 54 | +const notificationTime = ref<Time>(); |
| 55 | +
|
| 56 | +onMounted(async () => { |
| 57 | + showDailyNotifacation.value = await settingsStorage.getValue( |
| 58 | + StorageParams.DAILY_NOTIFICATION, |
| 59 | + DAILY_NOTIFICATION_DEFAULT, |
| 60 | + ); |
| 61 | +
|
| 62 | + dailyNotificationTime.value = (await settingsStorage.getValue( |
| 63 | + StorageParams.DAILY_SUMMARY_NOTIFICATION_TIME, |
| 64 | + DAILY_SUMMARY_NOTIFICATION_TIME_DEFAULT, |
| 65 | + )) as number; |
| 66 | +
|
| 67 | + const timeObj = convertSecondsToHHMM(dailyNotificationTime.value); |
| 68 | + notificationTime.value = timeObj; |
| 69 | +}); |
| 70 | +
|
| 71 | +function handleDate(modelData: Time) { |
| 72 | + if (modelData != null) { |
| 73 | + notificationTime.value = modelData; |
| 74 | + save( |
| 75 | + StorageParams.DAILY_SUMMARY_NOTIFICATION_TIME, |
| 76 | + convertHHMMToSeconds(notificationTime.value.hours, notificationTime.value.minutes), |
| 77 | + ); |
| 78 | + } |
| 79 | +} |
| 80 | +
|
| 81 | +async function onChange(storageParam: StorageParams, target: any) { |
| 82 | + if (target != null) await save(storageParam, target.checked); |
| 83 | +} |
| 84 | +
|
| 85 | +async function save(storageParam: StorageParams, value: any) { |
| 86 | + if (value != undefined) await settingsStorage.saveValue(storageParam, value); |
| 87 | +} |
| 88 | +</script> |
| 89 | + |
| 90 | +<style scoped> |
| 91 | +.date-picker { |
| 92 | + width: 120px; |
| 93 | + margin: 0 15px; |
| 94 | +} |
| 95 | +</style> |
0 commit comments