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 {hourToSalutation} from './hourToSalutation'
|
||||
import {hourToSalutation} from './useDateTimeSalutation'
|
||||
|
||||
const dateWithHour = (hours: number): Date => {
|
||||
const date = new Date()
|
||||
|
@ -30,5 +29,3 @@ describe('Salutation', () => {
|
|||
expect(salutation).toBe('home.welcomeNight')
|
||||
})
|
||||
})
|
||||
|
||||
|
|
@ -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<Date> = 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<Date> = useNow()): String {
|
|||
|
||||
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 {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)
|
||||
})
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue