diff --git a/src/helpers/hourToSalutation.test.ts b/src/composables/useDateTimeSalutation.test.ts similarity index 94% rename from src/helpers/hourToSalutation.test.ts rename to src/composables/useDateTimeSalutation.test.ts index 3297f71b..ecd48024 100644 --- a/src/helpers/hourToSalutation.test.ts +++ b/src/composables/useDateTimeSalutation.test.ts @@ -1,6 +1,5 @@ import {describe, it, expect} from 'vitest' - -import {hourToSalutation} from './hourToSalutation' +import {hourToSalutation} from './useDateTimeSalutation' const dateWithHour = (hours: number): Date => { const date = new Date() @@ -29,6 +28,4 @@ describe('Salutation', () => { const salutation = hourToSalutation(dateWithHour(23)) expect(salutation).toBe('home.welcomeNight') }) -}) - - +}) \ No newline at end of file diff --git a/src/helpers/hourToSalutation.ts b/src/composables/useDateTimeSalutation.ts similarity index 63% rename from src/helpers/hourToSalutation.ts rename to src/composables/useDateTimeSalutation.ts index 68a866f6..001c5d80 100644 --- a/src/helpers/hourToSalutation.ts +++ b/src/composables/useDateTimeSalutation.ts @@ -1,10 +1,10 @@ +import {computed} from 'vue' import {useNow} from '@vueuse/core' -import {Ref} from 'vue' const TRANSLATION_KEY_PREFIX = 'home.welcome' -export function hourToSalutation(now: Date | Ref = useNow()): String { - const hours = now instanceof Date ? new Date(now).getHours() : new Date(now.value).getHours() +export function hourToSalutation(now: Date) { + const hours = now.getHours() if (hours < 5) { return `${TRANSLATION_KEY_PREFIX}Night` @@ -24,3 +24,8 @@ export function hourToSalutation(now: Date | Ref = useNow()): String { return `${TRANSLATION_KEY_PREFIX}Night` } + +export function useDateTimeSalutation() { + const now = useNow() + return computed(() => hourToSalutation(now.value)) +} \ No newline at end of file diff --git a/src/views/Home.vue b/src/views/Home.vue index bb144922..f3d2b3ec 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -66,16 +66,15 @@ import AddTask from '@/components/tasks/add-task.vue' import {getHistory} from '@/modules/listHistory' import {parseDateOrNull} from '@/helpers/parseDateOrNull' import {formatDateShort, formatDateSince} from '@/helpers/time/formatDate' -import {hourToSalutation} from '@/helpers/hourToSalutation' +import {useDateTimeSalutation} from '@/composables/useDateTimeSalutation' -const welcome = computed(hourToSalutation) +const welcome = useDateTimeSalutation() const store = useStore() const listHistory = computed(() => { - const history = getHistory() - return history.map(l => { - return store.getters['lists/getListById'](l.id) - }).filter(l => l !== null) + return getHistory() + .map(l => store.getters['lists/getListById'](l.id)) + .filter(l => l !== null) })