From 3f69f84d194cb0b12bd39f8dd75cde4ad5296516 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 11 May 2026 18:16:59 -0500 Subject: [PATCH] Skeletonize account UI while metadata is loading While the kind-0 metadata query for logged-in accounts is in flight, we were rendering the genUserName-derived animal name (and its first letter as the avatar fallback) before falling back to the real display name once the profile arrived. That made the AccountSwitcher trigger flash a meaningless 'Brave Otter' / 'B' before settling on the real identity. Expose isLoading from useLoggedInAccounts and, while it is still true and we have no metadata.name yet, render Skeletons in place of: - the avatar fallback letter (in the AccountSwitcher trigger and the other-accounts dropdown rows), - the displayed name in the dropdown rows. Once the query settles, behavior is unchanged: a real name renders if present, otherwise the genUserName fallback fills in. --- src/components/auth/AccountSwitcher.tsx | 70 ++++++++++++++++++------- src/hooks/useLoggedInAccounts.ts | 3 +- 2 files changed, 52 insertions(+), 21 deletions(-) diff --git a/src/components/auth/AccountSwitcher.tsx b/src/components/auth/AccountSwitcher.tsx index 06aa143..383373a 100644 --- a/src/components/auth/AccountSwitcher.tsx +++ b/src/components/auth/AccountSwitcher.tsx @@ -7,6 +7,7 @@ import { DropdownMenuTrigger, } from '@/components/ui/dropdown-menu.tsx'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar.tsx'; +import { Skeleton } from '@/components/ui/skeleton.tsx'; import { useLoggedInAccounts, type Account } from '@/hooks/useLoggedInAccounts'; import { genUserName } from '@/lib/genUserName'; @@ -15,7 +16,7 @@ interface AccountSwitcherProps { } export function AccountSwitcher({ onAddAccountClick }: AccountSwitcherProps) { - const { currentUser, otherUsers, setLogin, removeLogin } = useLoggedInAccounts(); + const { currentUser, otherUsers, isLoading, setLogin, removeLogin } = useLoggedInAccounts(); if (!currentUser) return null; @@ -23,35 +24,64 @@ export function AccountSwitcher({ onAddAccountClick }: AccountSwitcherProps) { return account.metadata.name ?? genUserName(account.pubkey); } + // While the metadata query is in-flight and we don't yet have a name, + // we don't want to flash a generated animal name / its first letter. + const isCurrentUserPending = isLoading && !currentUser.metadata.name; + return (
Switch Account
- {otherUsers.map((user) => ( - setLogin(user.id)} - className='flex items-center gap-2 cursor-pointer p-2 rounded-md' - > - - - {getDisplayName(user)?.charAt(0) || } - -
-

{getDisplayName(user)}

-
- {user.id === currentUser.id &&
} -
- ))} + {otherUsers.map((user) => { + const isPending = isLoading && !user.metadata.name; + return ( + setLogin(user.id)} + className='flex items-center gap-2 cursor-pointer p-2 rounded-md' + > + + + + {isPending ? ( + + ) : ( + getDisplayName(user)?.charAt(0) || + )} + + +
+ {isPending ? ( + + ) : ( +

{getDisplayName(user)}

+ )} +
+ {user.id === currentUser.id &&
} +
+ ); + })}
); -} \ No newline at end of file +} diff --git a/src/hooks/useLoggedInAccounts.ts b/src/hooks/useLoggedInAccounts.ts index 9b639d9..c721584 100644 --- a/src/hooks/useLoggedInAccounts.ts +++ b/src/hooks/useLoggedInAccounts.ts @@ -14,7 +14,7 @@ export function useLoggedInAccounts() { const { nostr } = useNostr(); const { logins, setLogin, removeLogin } = useNostrLogin(); - const { data: authors = [] } = useQuery({ + const { data: authors = [], isLoading } = useQuery({ queryKey: ['nostr', 'logins', logins.map((l) => l.id).join(';')], queryFn: async () => { const events = await nostr.query( @@ -50,6 +50,7 @@ export function useLoggedInAccounts() { authors, currentUser, otherUsers, + isLoading, setLogin, removeLogin, };