feat: get username from store getter
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
import {computed, unref} from 'vue'
|
||||
import {computed} from 'vue'
|
||||
import {useI18n} from 'vue-i18n'
|
||||
import {useNow, type MaybeRef} from '@vueuse/core'
|
||||
import {useNow} from '@vueuse/core'
|
||||
|
||||
import {useAuthStore} from '@/stores/auth'
|
||||
|
||||
type Daytime = 'night' | 'morning' | 'day' | 'evening'
|
||||
|
||||
@ -12,17 +14,18 @@ export function hourToDaytime(now: Date): Daytime {
|
||||
morning: hours < 11,
|
||||
day: hours < 18,
|
||||
evening: hours < 23,
|
||||
} as Record<Daytime, boolean>
|
||||
} as Record<Daytime, boolean>
|
||||
|
||||
return (Object.keys(daytimeMap) as Daytime[]).find((daytime) => daytimeMap[daytime]) || 'night'
|
||||
}
|
||||
|
||||
export function useDateTimeSalutation(username: MaybeRef<string>) {
|
||||
export function useDateTimeSalutation() {
|
||||
const {t} = useI18n({useScope: 'global'})
|
||||
const now = useNow()
|
||||
|
||||
const authStore = useAuthStore()
|
||||
|
||||
const name = computed(() => authStore.userDisplayName)
|
||||
const daytime = computed(() => hourToDaytime(now.value))
|
||||
const name = computed(() => unref(username))
|
||||
|
||||
const salutations = {
|
||||
'night': () => t('home.welcomeNight', {username: name.value}),
|
||||
@ -31,5 +34,5 @@ export function useDateTimeSalutation(username: MaybeRef<string>) {
|
||||
'evening': () => t('home.welcomeEvening', {username: name.value}),
|
||||
} as Record<Daytime, () => string>
|
||||
|
||||
return computed(() => salutations[daytime.value]())
|
||||
return computed(() => name.value ? salutations[daytime.value]() : undefined)
|
||||
}
|
Reference in New Issue
Block a user