From 6c48e7c6845a51002a89eebf88a76b71e6326979 Mon Sep 17 00:00:00 2001 From: sam Date: Mon, 20 Oct 2025 21:33:38 +0700 Subject: [PATCH] better loading feedback in the ui --- src/components/dm/DMConversationList.tsx | 67 +++++++++++++++--------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/src/components/dm/DMConversationList.tsx b/src/components/dm/DMConversationList.tsx index 231190c..ba5e10e 100644 --- a/src/components/dm/DMConversationList.tsx +++ b/src/components/dm/DMConversationList.tsx @@ -1,5 +1,5 @@ import { useMemo, useState, memo } from 'react'; -import { AlertTriangle, Info } from 'lucide-react'; +import { AlertTriangle, Info, Loader2 } from 'lucide-react'; import { useDMContext } from '@/contexts/DMContext'; import { useAuthor } from '@/hooks/useAuthor'; import { genUserName } from '@/lib/genUserName'; @@ -10,6 +10,7 @@ import { ScrollArea } from '@/components/ui/scroll-area'; import { Skeleton } from '@/components/ui/skeleton'; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'; import { cn } from '@/lib/utils'; +import { LOADING_PHASES } from '@/lib/dmConstants'; interface DMConversationListProps { selectedPubkey: string | null; @@ -173,7 +174,7 @@ export const DMConversationList = ({ className, onStatusClick }: DMConversationListProps) => { - const { conversations, isLoading } = useDMContext(); + const { conversations, isLoading, loadingPhase } = useDMContext(); const [activeTab, setActiveTab] = useState<'known' | 'requests'>('known'); // Filter conversations by type @@ -187,29 +188,36 @@ export const DMConversationList = ({ // Get the current list based on active tab const currentConversations = activeTab === 'known' ? knownConversations : requestConversations; - if (isLoading) { - return ( - - - - ); - } - - if (conversations.length === 0) { - return ( - -
-

No conversations yet

-

Start a new conversation to get started

-
-
- ); - } + // Show skeleton during initial load (cache + relays) if we have no conversations yet + const isInitialLoad = (loadingPhase === LOADING_PHASES.CACHE || loadingPhase === LOADING_PHASES.RELAYS) && conversations.length === 0; return ( + {/* Header - always visible */}
-

Messages

+
+

Messages

+ {(loadingPhase === LOADING_PHASES.CACHE || + loadingPhase === LOADING_PHASES.RELAYS || + loadingPhase === LOADING_PHASES.SUBSCRIPTIONS) && ( + + + +
+ +
+
+ +

+ {loadingPhase === LOADING_PHASES.CACHE && 'Loading from cache...'} + {loadingPhase === LOADING_PHASES.RELAYS && 'Querying relays for new messages...'} + {loadingPhase === LOADING_PHASES.SUBSCRIPTIONS && 'Setting up subscriptions...'} +

+
+
+
+ )} +
{onStatusClick && (
- {/* Single shared container */} + {/* Content area - show skeleton during initial load, otherwise show conversations */}
- {currentConversations.length === 0 ? ( + {(isLoading || isInitialLoad) ? ( + + ) : conversations.length === 0 ? ( +
+
+

No conversations yet

+

Start a new conversation to get started

+
+
+ ) : currentConversations.length === 0 ? (
-

No conversations

+

No {activeTab} conversations

) : (