|
| 1 | +<template> |
| 2 | + <p class="title mt-0">{{ t('pomodoro.message') }}</p> |
| 3 | + <p class="description"> |
| 4 | + {{ t('pomodoro.description') }} |
| 5 | + </p> |
| 6 | + <div class="pomodoro-block mt-20"> |
| 7 | + <p class="title">{{ t('pomodoroWork.message') }}</p> |
| 8 | + <VueDatePicker v-model="workTime" time-picker class="date-picker" /> |
| 9 | + </div> |
| 10 | + <div class="pomodoro-block"> |
| 11 | + <p class="title">{{ t('pomodoroRest.message') }}</p> |
| 12 | + <VueDatePicker v-model="restTime" time-picker class="date-picker" /> |
| 13 | + </div> |
| 14 | + <div class="pomodoro-block"> |
| 15 | + <p class="title">{{ t('pomodoroFrequency.message') }}</p> |
| 16 | + <input type="number" class="frequency" v-model="frequency" /> |
| 17 | + </div> |
| 18 | + <button |
| 19 | + class="d-inline-block mt-15" |
| 20 | + :class="isEnabled ? 'stop' : 'start'" |
| 21 | + @click="changeStatus()" |
| 22 | + > |
| 23 | + <img v-if="isEnabled" class="ml-5" src="../assets/icons/stop.svg" height="20" /> |
| 24 | + <img v-if="!isEnabled" class="ml-5" src="../assets/icons/start.svg" height="22" /> |
| 25 | + {{ !isEnabled ? t('start.message') : t('stop.message') }} |
| 26 | + </button> |
| 27 | +</template> |
| 28 | + |
| 29 | +<script lang="ts"></script> |
| 30 | + |
| 31 | +<script lang="ts" setup> |
| 32 | +import { onMounted, ref } from 'vue'; |
| 33 | +import { convertHHMMToSeconds, convertSecondsToHHMM } from '../utils/converter'; |
| 34 | +import { useI18n } from 'vue-i18n'; |
| 35 | +import { injecStorage } from '../storage/inject-storage'; |
| 36 | +import { |
| 37 | + IS_POMODORO_ENABLED_DEFAULT, |
| 38 | + POMODORO_FREQUENCY_DEFAULT, |
| 39 | + POMODORO_INTERVAL_REST_DEFAULT, |
| 40 | + POMODORO_INTERVAL_WORK_DEFAULT, |
| 41 | + StorageParams, |
| 42 | +} from '../storage/storage-params'; |
| 43 | +import { Time } from '../utils/time'; |
| 44 | +import { logger } from '../utils/logger'; |
| 45 | +
|
| 46 | +const { t } = useI18n(); |
| 47 | +const settingsStorage = injecStorage(); |
| 48 | +
|
| 49 | +const workTime = ref<Time>({ |
| 50 | + hours: 0, |
| 51 | + minutes: 25, |
| 52 | +}); |
| 53 | +const restTime = ref<Time>({ |
| 54 | + hours: 0, |
| 55 | + minutes: 5, |
| 56 | +}); |
| 57 | +const frequency = ref<number>(3); |
| 58 | +const isEnabled = ref<boolean>(); |
| 59 | +
|
| 60 | +onMounted(async () => { |
| 61 | + isEnabled.value = await settingsStorage.getValue( |
| 62 | + StorageParams.IS_POMODORO_ENABLED, |
| 63 | + IS_POMODORO_ENABLED_DEFAULT, |
| 64 | + ); |
| 65 | + workTime.value = convertSecondsToHHMM( |
| 66 | + await settingsStorage.getValue( |
| 67 | + StorageParams.POMODORO_INTERVAL_WORK, |
| 68 | + POMODORO_INTERVAL_WORK_DEFAULT, |
| 69 | + ), |
| 70 | + ); |
| 71 | + restTime.value = convertSecondsToHHMM( |
| 72 | + await settingsStorage.getValue( |
| 73 | + StorageParams.POMODORO_INTERVAL_REST, |
| 74 | + POMODORO_INTERVAL_REST_DEFAULT, |
| 75 | + ), |
| 76 | + ); |
| 77 | + frequency.value = await settingsStorage.getValue( |
| 78 | + StorageParams.POMODORO_FREQUENCY, |
| 79 | + POMODORO_FREQUENCY_DEFAULT, |
| 80 | + ); |
| 81 | +}); |
| 82 | +
|
| 83 | +async function changeStatus() { |
| 84 | + await settingsStorage.saveValue(StorageParams.IS_POMODORO_ENABLED, !isEnabled.value); |
| 85 | + await settingsStorage.saveValue( |
| 86 | + StorageParams.POMODORO_INTERVAL_WORK, |
| 87 | + convertHHMMToSeconds(workTime.value.hours, workTime.value.minutes), |
| 88 | + ); |
| 89 | + await settingsStorage.saveValue( |
| 90 | + StorageParams.POMODORO_INTERVAL_REST, |
| 91 | + convertHHMMToSeconds(restTime.value.hours, restTime.value.minutes), |
| 92 | + ); |
| 93 | + await settingsStorage.saveValue(StorageParams.POMODORO_START_TIME, new Date()); |
| 94 | + await settingsStorage.saveValue(StorageParams.POMODORO_FREQUENCY, frequency.value); |
| 95 | +
|
| 96 | + isEnabled.value = !isEnabled.value; |
| 97 | +
|
| 98 | + logger.log(`Change pomodoro status to ${String(isEnabled.value).toUpperCase()}`); |
| 99 | +} |
| 100 | +</script> |
| 101 | + |
| 102 | +<style scoped> |
| 103 | +.pomodoro-block { |
| 104 | + display: flex; |
| 105 | + justify-content: start; |
| 106 | +} |
| 107 | +.date-picker { |
| 108 | + width: 120px; |
| 109 | + margin: 0 15px; |
| 110 | + vertical-align: center; |
| 111 | + padding: 10px 0; |
| 112 | +} |
| 113 | +.frequency { |
| 114 | + width: 50px; |
| 115 | + padding: 5px 10px; |
| 116 | + height: 20px; |
| 117 | + margin: auto 0; |
| 118 | + margin-left: 15px; |
| 119 | +} |
| 120 | +.blocked { |
| 121 | + display: inline-block; |
| 122 | + font-size: 13px; |
| 123 | + color: gray; |
| 124 | + margin-left: 55px; |
| 125 | + margin-top: 5px; |
| 126 | +} |
| 127 | +button { |
| 128 | + color: white !important; |
| 129 | + border: none; |
| 130 | +} |
| 131 | +button.start { |
| 132 | + background-color: rgb(62, 148, 62) !important; |
| 133 | +} |
| 134 | +button.stop { |
| 135 | + background-color: rgb(191, 59, 59) !important; |
| 136 | +} |
| 137 | +</style> |
0 commit comments