feat: convert to composable useDateTimeSalutation
This commit is contained in:
parent
d2577f1df6
commit
cb37fd773d
3 changed files with 15 additions and 14 deletions
|
@ -1,6 +1,5 @@
|
||||||
import {describe, it, expect} from 'vitest'
|
import {describe, it, expect} from 'vitest'
|
||||||
|
import {hourToSalutation} from './useDateTimeSalutation'
|
||||||
import {hourToSalutation} from './hourToSalutation'
|
|
||||||
|
|
||||||
const dateWithHour = (hours: number): Date => {
|
const dateWithHour = (hours: number): Date => {
|
||||||
const date = new Date()
|
const date = new Date()
|
||||||
|
@ -29,6 +28,4 @@ describe('Salutation', () => {
|
||||||
const salutation = hourToSalutation(dateWithHour(23))
|
const salutation = hourToSalutation(dateWithHour(23))
|
||||||
expect(salutation).toBe('home.welcomeNight')
|
expect(salutation).toBe('home.welcomeNight')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
|
import {computed} from 'vue'
|
||||||
import {useNow} from '@vueuse/core'
|
import {useNow} from '@vueuse/core'
|
||||||
import {Ref} from 'vue'
|
|
||||||
|
|
||||||
const TRANSLATION_KEY_PREFIX = 'home.welcome'
|
const TRANSLATION_KEY_PREFIX = 'home.welcome'
|
||||||
|
|
||||||
export function hourToSalutation(now: Date | Ref<Date> = useNow()): String {
|
export function hourToSalutation(now: Date) {
|
||||||
const hours = now instanceof Date ? new Date(now).getHours() : new Date(now.value).getHours()
|
const hours = now.getHours()
|
||||||
|
|
||||||
if (hours < 5) {
|
if (hours < 5) {
|
||||||
return `${TRANSLATION_KEY_PREFIX}Night`
|
return `${TRANSLATION_KEY_PREFIX}Night`
|
||||||
|
@ -24,3 +24,8 @@ export function hourToSalutation(now: Date | Ref<Date> = useNow()): String {
|
||||||
|
|
||||||
return `${TRANSLATION_KEY_PREFIX}Night`
|
return `${TRANSLATION_KEY_PREFIX}Night`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useDateTimeSalutation() {
|
||||||
|
const now = useNow()
|
||||||
|
return computed(() => hourToSalutation(now.value))
|
||||||
|
}
|
|
@ -66,16 +66,15 @@ import AddTask from '@/components/tasks/add-task.vue'
|
||||||
import {getHistory} from '@/modules/listHistory'
|
import {getHistory} from '@/modules/listHistory'
|
||||||
import {parseDateOrNull} from '@/helpers/parseDateOrNull'
|
import {parseDateOrNull} from '@/helpers/parseDateOrNull'
|
||||||
import {formatDateShort, formatDateSince} from '@/helpers/time/formatDate'
|
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 store = useStore()
|
||||||
const listHistory = computed(() => {
|
const listHistory = computed(() => {
|
||||||
const history = getHistory()
|
return getHistory()
|
||||||
return history.map(l => {
|
.map(l => store.getters['lists/getListById'](l.id))
|
||||||
return store.getters['lists/getListById'](l.id)
|
.filter(l => l !== null)
|
||||||
}).filter(l => l !== null)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue