2023-03-24 19:06:08 +00:00
|
|
|
import {computed, onActivated, ref} from 'vue'
|
2022-10-16 13:26:02 +00:00
|
|
|
import {useI18n} from 'vue-i18n'
|
2022-10-16 17:36:04 +00:00
|
|
|
|
|
|
|
import {useAuthStore} from '@/stores/auth'
|
2022-10-17 00:12:32 +00:00
|
|
|
import {hourToDaytime} from '@/helpers/hourToDaytime'
|
2021-12-30 16:18:57 +00:00
|
|
|
|
2022-10-17 00:12:32 +00:00
|
|
|
export type Daytime = 'night' | 'morning' | 'day' | 'evening'
|
2021-12-30 16:14:43 +00:00
|
|
|
|
2022-10-17 00:12:32 +00:00
|
|
|
export function useDaytimeSalutation() {
|
2022-10-16 13:26:02 +00:00
|
|
|
const {t} = useI18n({useScope: 'global'})
|
2023-03-24 18:48:53 +00:00
|
|
|
const now = ref(new Date())
|
2023-03-24 19:06:08 +00:00
|
|
|
onActivated(() => now.value = new Date())
|
2022-10-16 17:36:04 +00:00
|
|
|
const authStore = useAuthStore()
|
|
|
|
|
|
|
|
const name = computed(() => authStore.userDisplayName)
|
2022-10-16 13:26:02 +00:00
|
|
|
const daytime = computed(() => hourToDaytime(now.value))
|
|
|
|
|
|
|
|
const salutations = {
|
|
|
|
'night': () => t('home.welcomeNight', {username: name.value}),
|
|
|
|
'morning': () => t('home.welcomeMorning', {username: name.value}),
|
|
|
|
'day': () => t('home.welcomeDay', {username: name.value}),
|
|
|
|
'evening': () => t('home.welcomeEvening', {username: name.value}),
|
|
|
|
} as Record<Daytime, () => string>
|
|
|
|
|
2022-10-16 17:36:04 +00:00
|
|
|
return computed(() => name.value ? salutations[daytime.value]() : undefined)
|
2022-01-04 16:54:00 +00:00
|
|
|
}
|