forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotifications.vue
More file actions
142 lines (128 loc) · 4.14 KB
/
Notifications.vue
File metadata and controls
142 lines (128 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<template>
<div>
<div class="settings-item">
<label class="setting-header">
<input
type="checkbox"
class="filled-in"
id="blockDeferral"
v-model="showDailyNotifacation"
@change="onChange(StorageParams.DAILY_NOTIFICATION, $event.target)"
/>
<span>{{ t('showDailyNotifacation.message') }}</span>
<p class="description">
{{ t('showDailyNotifacation.description') }}
</p>
</label>
</div>
<div class="settings-item">
<p class="setting-header d-inline-block">
{{ t('notificationTimeSetting.message') }}
</p>
<VueDatePicker
v-model="notificationTime"
time-picker
@update:model-value="handleDate"
class="date-picker d-inline-block"
/>
</div>
<div class="settings-item">
<label class="setting-header">{{ t('notificationTime.message') }}</label>
<p class="description">
{{ t('notificationTime.description') }}
</p>
<ListWithTimeComponent :type="ListWithTime.Notifications" />
</div>
<div class="settings-item">
<label class="setting-header">{{ t('notificationMessage.message') }}</label>
<p class="description">
{{ t('notificationMessage.description') }}
</p>
<input
type="text"
class=""
:placeholder="t('enterNotification.message')"
v-model="notificationMessage"
/>
<input
type="button"
class="d-inline-block small-btn ml-10 width"
:value="t('save.message')"
:disabled="notificationMessage == ''"
@click="saveNotificationMessage()"
/>
</div>
</div>
</template>
<script lang="ts">
export default {
name: 'DailyNotifications',
};
</script>
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { injecStorage } from '../storage/inject-storage';
import { NOTIFICATION_MESSAGE_DEFAULT, StorageParams } from '../storage/storage-params';
import {
DAILY_NOTIFICATION_DEFAULT,
DAILY_SUMMARY_NOTIFICATION_TIME_DEFAULT,
} from '../storage/storage-params';
import { convertHHMMToSeconds, convertSecondsToHHMM } from '../utils/converter';
import { Time } from '../utils/time';
import ListWithTimeComponent from '../components/ListWithTime.vue';
import PromoClearYouTube from '../components/PromoClearYouTube.vue';
import { ListWithTime } from '../utils/enums';
import Browser from 'webextension-polyfill';
import { Messages } from '../utils/messages';
const { t } = useI18n();
const settingsStorage = injecStorage();
const showDailyNotifacation = ref<boolean>();
const dailyNotificationTime = ref<number>();
const notificationTime = ref<Time>();
const notificationMessage = ref<string>();
onMounted(async () => {
showDailyNotifacation.value = await settingsStorage.getValue(
StorageParams.DAILY_NOTIFICATION,
DAILY_NOTIFICATION_DEFAULT,
);
notificationMessage.value = await settingsStorage.getValue(
StorageParams.NOTIFICATION_MESSAGE,
NOTIFICATION_MESSAGE_DEFAULT,
);
dailyNotificationTime.value = (await settingsStorage.getValue(
StorageParams.DAILY_SUMMARY_NOTIFICATION_TIME,
DAILY_SUMMARY_NOTIFICATION_TIME_DEFAULT,
)) as number;
const timeObj = convertSecondsToHHMM(dailyNotificationTime.value);
notificationTime.value = timeObj;
});
async function saveNotificationMessage() {
save(StorageParams.NOTIFICATION_MESSAGE, notificationMessage.value);
}
async function handleDate(modelData: Time) {
if (modelData != null) {
notificationTime.value = modelData;
await save(
StorageParams.DAILY_SUMMARY_NOTIFICATION_TIME,
convertHHMMToSeconds(notificationTime.value.hours, notificationTime.value.minutes),
);
Browser.runtime.sendMessage(Messages.RescheduleJobs);
}
}
async function onChange(storageParam: StorageParams, target: any) {
if (target != null) await save(storageParam, target.checked);
}
async function save(storageParam: StorageParams, value: any) {
if (value != undefined) await settingsStorage.saveValue(storageParam, value);
}
</script>
<style scoped>
.date-picker {
width: 120px;
margin: 0 15px;
}
.width {
width: 540px;
}
</style>