Skip to content

Commit cdfcc9a

Browse files
committed
Daily notifcation setting
1 parent 64fbf35 commit cdfcc9a

File tree

5 files changed

+103
-5
lines changed

5 files changed

+103
-5
lines changed

src/components/Limits.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ import { isDomainEquals } from '../utils/common';
6161
import { extractHostname } from '../compositions/extract-hostname';
6262
import { Restriction } from '../entity/restriction';
6363
import { convertHHMMToSeconds, convertSecondsToHHMM } from '../utils/converter';
64+
import { Time } from '../utils/time';
6465
6566
const notification = useNotification();
6667
6768
const settingsStorage = injecStorage();
6869
6970
const limitList = ref<Restriction[]>();
70-
const time = ref({
71+
const time = ref<Time>({
7172
hours: 0,
7273
minutes: 30,
7374
});

src/components/Notifications.vue

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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>

src/pages/Dashboard.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
<label name="tabName" for="notification-tab">Notifications</label>
5858

5959
<div class="settings-content">
60-
<Notifications v-if="selectedTab == SettingsTab.Notifications" />
60+
<DailyNotifications v-if="selectedTab == SettingsTab.Notifications" />
6161
</div>
6262
</div>
6363

@@ -82,6 +82,7 @@ import { onMounted, ref } from 'vue';
8282
import GeneralSettings from '../components/GeneralSettings.vue';
8383
import WhiteList from '../components/WhiteList.vue';
8484
import Limits from '../components/Limits.vue';
85+
import DailyNotifications from '../components/Notifications.vue';
8586
import About from '../components/About.vue';
8687
import { SettingsTab } from '../utils/enums';
8788

src/storage/storage-params.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export enum StorageParams {
1313
BLOCK_DEFERRAL = 'view_block_deferral',
1414
BLOCK_DEFERRAL_TIME = 'view_block_deferral_time',
1515
DAILY_SUMMARY_NOTIFICATION_TIME = 'daily-summary-notification-time',
16+
DAILY_NOTIFICATION = 'daily_notification',
1617
}
1718

1819
export enum StorageDeserializeParam {
@@ -51,8 +52,9 @@ export const DARK_MODE_DEFAULT = false;
5152
export const VIEW_TIME_IN_BADGE_DEFAULT = true;
5253
export const BLOCK_DEFERRAL_DEFAULT = true;
5354
export const SHOW_HINT_DEFAULT = true;
54-
// default time is 20:00, time in miliseconds
55-
export const DAILY_SUMMARY_NOTIFICATION_TIME_DEFAULT = 20 * HOUR;
55+
// default time is 20:00, time in seconds
56+
export const DAILY_SUMMARY_NOTIFICATION_TIME_DEFAULT = (20 * HOUR) / 1000;
57+
export const DAILY_NOTIFICATION_DEFAULT = true;
5658

5759
export function getDefaultValue(param: StorageParams) {
5860
switch (param) {

src/utils/converter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { min } from 'date-fns';
21
import { Time } from './time';
32

43
export function convertHHMMToSeconds(hours: number, minutes: number) {

0 commit comments

Comments
 (0)