diff --git a/src/composables/useDateTimeSalutation.ts b/src/composables/useDateTimeSalutation.ts index af1f0cd9cb..a1d914dc51 100644 --- a/src/composables/useDateTimeSalutation.ts +++ b/src/composables/useDateTimeSalutation.ts @@ -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 + } as Record return (Object.keys(daytimeMap) as Daytime[]).find((daytime) => daytimeMap[daytime]) || 'night' } -export function useDateTimeSalutation(username: MaybeRef) { +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) { 'evening': () => t('home.welcomeEvening', {username: name.value}), } as Record string> - return computed(() => salutations[daytime.value]()) + return computed(() => name.value ? salutations[daytime.value]() : undefined) } \ No newline at end of file diff --git a/src/stores/auth.ts b/src/stores/auth.ts index ace2e4d514..b9c16bad5f 100644 --- a/src/stores/auth.ts +++ b/src/stores/auth.ts @@ -3,7 +3,7 @@ import {defineStore, acceptHMRUpdate} from 'pinia' import {HTTPFactory, AuthenticatedHTTPFactory} from '@/http-common' import {i18n, getCurrentLanguage, saveLanguage} from '@/i18n' import {objectToSnakeCase} from '@/helpers/case' -import UserModel, { getAvatarUrl } from '@/models/user' +import UserModel, { getAvatarUrl, getDisplayName } from '@/models/user' import UserSettingsService from '@/services/userSettings' import {getToken, refreshToken, removeToken, saveToken} from '@/helpers/auth' import {setModuleLoading} from '@/stores/helper' @@ -54,6 +54,9 @@ export const useAuthStore = defineStore('auth', { state.info.type === AUTH_TYPES.LINK_SHARE ) }, + userDisplayName(state) { + return state.info ? getDisplayName(state.info) : undefined + }, }, actions: { setIsLoading(isLoading: boolean) { diff --git a/src/views/Home.vue b/src/views/Home.vue index c8dcd0d3ad..77a0263089 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -1,8 +1,7 @@