11<script setup lang="ts">
2- import type { UserResource } from ' @/types/resources' ;
3-
4- import { ref , onMounted , watch } from ' vue' ;
2+ import { ref , onMounted } from ' vue' ;
53import { useAuthStore } from ' @/stores/AuthStore' ;
64import { useAppStore } from ' @/stores/AppStore' ;
75import { storeToRefs } from ' pinia' ;
@@ -20,24 +18,18 @@ import ProiconsMenu from '~icons/proicons/menu';
2018const showDropdown = ref (false );
2119const username = ref (' ' );
2220
21+ const { userData, isLoadingUserData } = storeToRefs (useAuthStore ());
2322const { pageTitle, selectedSideBar } = storeToRefs (useAppStore ());
2423const { cycleSideBar } = useAppStore ();
25- const { userData } = storeToRefs (useAuthStore ());
2624const { auth } = useAuthStore ();
2725
2826const toggleDropdown = () => {
2927 showDropdown .value = ! showDropdown .value ;
3028};
3129
32- const handleAuthEvent = (newUserData : UserResource | null ) => {
33- username .value = newUserData ?.name ?? ' ' ;
34- };
35-
3630onMounted (async () => {
37- if ( await auth ()) handleAuthEvent ( userData . value );
31+ await auth ();
3832});
39-
40- watch (userData , handleAuthEvent , { immediate: false });
4133 </script >
4234
4335<template >
@@ -55,8 +47,13 @@ watch(userData, handleAuthEvent, { immediate: false });
5547 :aria-expanded =" showDropdown"
5648 aria-controls =" user-dropdown"
5749 >
58- <h2 id =" user-name" class =" hidden sm:block truncate" v-if =" username" >{{ username }}</h2 >
59- <h2 id =" user-name-unauth" v-else class =" text-right hidden sm:block" >Guest</h2 >
50+ <h2
51+ id =" user-name"
52+ class =" hidden sm:block truncate"
53+ :class =" [{ 'bg-neutral-200 dark:bg-neutral-800 rounded-full w-32 h-5 my-auto animate-pulse': isLoadingUserData }]"
54+ >
55+ {{ isLoadingUserData ? '' : userData?.name || 'Guest' }}
56+ </h2 >
6057
6158 <img
6259 :src =" userData?.avatar ?? '/storage/avatars/default.jpg'"
@@ -69,7 +66,7 @@ watch(userData, handleAuthEvent, { immediate: false });
6966 </span >
7067 <span class =" flex flex-wrap sm:flex-nowrap sm:max-w-sm items-center gap-1 sm:shrink-0 justify-end sm:justify-normal sm:w-auto ml-auto" >
7168 <section id =" video-navbar" class =" flex items-center gap-1 antialiased" >
72- <NavButton v-if =" username " @click =" cycleSideBar (' notifications' )" :label =" ' notifications' " class="hidden">
69+ <NavButton v-if =" userData " @click =" cycleSideBar (' notifications' )" :label =" ' notifications' " class="hidden">
7370 <template #icon >
7471 <CircumInboxIn height="24" width="24" />
7572 </template >
0 commit comments