From 9d3ead4428ce3f8cf106f87e1d8b29e3100fd931 Mon Sep 17 00:00:00 2001 From: sam Date: Sat, 18 Oct 2025 20:18:35 +0700 Subject: [PATCH] fix scroll and use a warn for nip4 messages --- src/components/dm/ConversationList.tsx | 149 ++++++++++++++----------- src/components/ui/scroll-area.tsx | 2 +- 2 files changed, 84 insertions(+), 67 deletions(-) diff --git a/src/components/dm/ConversationList.tsx b/src/components/dm/ConversationList.tsx index 5051e4d..5f4ff24 100644 --- a/src/components/dm/ConversationList.tsx +++ b/src/components/dm/ConversationList.tsx @@ -1,13 +1,13 @@ -import { useMemo } from 'react'; +import { useMemo, useState } from 'react'; +import { AlertTriangle } from 'lucide-react'; import { useDMContext } from '@/contexts/DMContext'; import { useAuthor } from '@/hooks/useAuthor'; import { genUserName } from '@/lib/genUserName'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; -import { Badge } from '@/components/ui/badge'; import { Card } from '@/components/ui/card'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Skeleton } from '@/components/ui/skeleton'; -import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; +import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'; import { cn } from '@/lib/utils'; interface ConversationListProps { @@ -22,14 +22,14 @@ const ConversationItem = ({ onClick, lastMessage, lastActivity, - hasNIP17Messages + hasNIP4Messages }: { pubkey: string; isSelected: boolean; onClick: () => void; lastMessage: { decryptedContent?: string; error?: string } | null; lastActivity: number; - hasNIP17Messages: boolean; + hasNIP4Messages: boolean; }) => { const author = useAuthor(pubkey); const metadata = author.data?.metadata; @@ -56,17 +56,17 @@ const ConversationItem = ({ const lastMessagePreview = lastMessage?.error ? '🔒 Encrypted message' - : lastMessage?.decryptedContent?.slice(0, 30) || 'No messages yet'; + : lastMessage?.decryptedContent || 'No messages yet'; return ( @@ -121,6 +130,7 @@ export const ConversationList = ({ className }: ConversationListProps) => { const { conversations, isLoading } = useDMContext(); + const [activeTab, setActiveTab] = useState<'known' | 'requests'>('known'); // Filter conversations by type const { knownConversations, requestConversations } = useMemo(() => { @@ -130,33 +140,8 @@ export const ConversationList = ({ }; }, [conversations]); - const renderConversationList = (conversationList: typeof conversations) => { - if (conversationList.length === 0) { - return ( -
-

No conversations

-
- ); - } - - return ( - -
- {conversationList.map((conversation) => ( - onSelectConversation(conversation.pubkey)} - lastMessage={conversation.lastMessage} - lastActivity={conversation.lastActivity} - hasNIP17Messages={conversation.hasNIP17Messages} - /> - ))} -
-
- ); - }; + // Get the current list based on active tab + const currentConversations = activeTab === 'known' ? knownConversations : requestConversations; if (isLoading) { return ( @@ -183,26 +168,58 @@ export const ConversationList = ({

Messages

- -
- - - Active {knownConversations.length > 0 && `(${knownConversations.length})`} - - - Requests {requestConversations.length > 0 && `(${requestConversations.length})`} - - + {/* Tab buttons */} +
+
+ +
- - - {renderConversationList(knownConversations)} - - - - {renderConversationList(requestConversations)} - - +
+ + {/* Single shared container */} +
+ {currentConversations.length === 0 ? ( +
+

No conversations

+
+ ) : ( + +
+ {currentConversations.map((conversation) => ( + onSelectConversation(conversation.pubkey)} + lastMessage={conversation.lastMessage} + lastActivity={conversation.lastActivity} + hasNIP4Messages={conversation.hasNIP4Messages} + /> + ))} +
+
+ )} +
); }; diff --git a/src/components/ui/scroll-area.tsx b/src/components/ui/scroll-area.tsx index cf253cf..cff30bf 100644 --- a/src/components/ui/scroll-area.tsx +++ b/src/components/ui/scroll-area.tsx @@ -12,7 +12,7 @@ const ScrollArea = React.forwardRef< className={cn("relative overflow-hidden", className)} {...props} > - + {children}