mirror of
https://gitlab.com/soapbox-pub/mkstack.git
synced 2026-12-03 08:07:21 +00:00
fix sixing of conversation list items
This commit is contained in:
1 parent
114eb13ce6
commit
9e222850ce
1 file changed
+75
-31
@@ -1,3 +1,4 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useDMContext } from '@/contexts/DMContext';
|
||||
import { useAuthor } from '@/hooks/useAuthor';
|
||||
import { genUserName } from '@/lib/genUserName';
|
||||
@@ -6,6 +7,7 @@ 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 { cn } from '@/lib/utils';
|
||||
|
||||
interface ConversationListProps {
|
||||
@@ -41,22 +43,26 @@ const ConversationItem = ({
|
||||
const now = Date.now() / 1000;
|
||||
const diff = now - timestamp;
|
||||
|
||||
if (diff < 60) return 'Just now';
|
||||
if (diff < 3600) return `${Math.floor(diff / 60)}m ago`;
|
||||
if (diff < 86400) return `${Math.floor(diff / 3600)}h ago`;
|
||||
if (diff < 604800) return `${Math.floor(diff / 86400)}d ago`;
|
||||
return new Date(timestamp * 1000).toLocaleDateString();
|
||||
if (diff < 60) return 'now';
|
||||
if (diff < 3600) return `${Math.floor(diff / 60)}m`;
|
||||
if (diff < 86400) return `${Math.floor(diff / 3600)}h`;
|
||||
if (diff < 604800) return `${Math.floor(diff / 86400)}d`;
|
||||
|
||||
const date = new Date(timestamp * 1000);
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
return `${month}/${day}`;
|
||||
};
|
||||
|
||||
const lastMessagePreview = lastMessage?.error
|
||||
? '🔒 Encrypted message'
|
||||
: lastMessage?.decryptedContent?.slice(0, 50) || 'No messages yet';
|
||||
: lastMessage?.decryptedContent?.slice(0, 30) || 'No messages yet';
|
||||
|
||||
return (
|
||||
<button
|
||||
onClick={onClick}
|
||||
className={cn(
|
||||
"w-full text-left p-3 rounded-lg transition-colors hover:bg-accent",
|
||||
"w-full text-left p-3 rounded-lg transition-colors hover:bg-accent overflow-hidden",
|
||||
isSelected && "bg-accent"
|
||||
)}
|
||||
>
|
||||
@@ -69,18 +75,18 @@ const ConversationItem = ({
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center justify-between gap-2 mb-1">
|
||||
<span className="font-medium text-sm truncate">{displayName}</span>
|
||||
<span className="text-xs text-muted-foreground flex-shrink-0">
|
||||
<span className="text-xs text-muted-foreground flex-shrink-0 whitespace-nowrap">
|
||||
{formatTime(lastActivity)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<p className="text-sm text-muted-foreground truncate flex-1">
|
||||
<span className="text-sm text-muted-foreground truncate flex-1">
|
||||
{lastMessagePreview}
|
||||
</p>
|
||||
</span>
|
||||
{hasNIP17Messages && (
|
||||
<Badge variant="secondary" className="text-xs flex-shrink-0">
|
||||
NIP-17
|
||||
<Badge variant="secondary" className="text-[10px] px-1.5 py-0 h-4 flex-shrink-0">
|
||||
17
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
@@ -116,6 +122,42 @@ export const ConversationList = ({
|
||||
}: ConversationListProps) => {
|
||||
const { conversations, isLoading } = useDMContext();
|
||||
|
||||
// Filter conversations by type
|
||||
const { knownConversations, requestConversations } = useMemo(() => {
|
||||
return {
|
||||
knownConversations: conversations.filter(c => c.isKnown),
|
||||
requestConversations: conversations.filter(c => c.isRequest),
|
||||
};
|
||||
}, [conversations]);
|
||||
|
||||
const renderConversationList = (conversationList: typeof conversations) => {
|
||||
if (conversationList.length === 0) {
|
||||
return (
|
||||
<div className="flex items-center justify-center h-32 text-center text-muted-foreground px-4">
|
||||
<p className="text-sm">No conversations</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<ScrollArea className="flex-1 h-full">
|
||||
<div className="px-2 py-2 space-y-1 w-full">
|
||||
{conversationList.map((conversation) => (
|
||||
<ConversationItem
|
||||
key={conversation.pubkey}
|
||||
pubkey={conversation.pubkey}
|
||||
isSelected={selectedPubkey === conversation.pubkey}
|
||||
onClick={() => onSelectConversation(conversation.pubkey)}
|
||||
lastMessage={conversation.lastMessage}
|
||||
lastActivity={conversation.lastActivity}
|
||||
hasNIP17Messages={conversation.hasNIP17Messages}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
);
|
||||
};
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<Card className={cn("h-full", className)}>
|
||||
@@ -136,29 +178,31 @@ export const ConversationList = ({
|
||||
}
|
||||
|
||||
return (
|
||||
<Card className={cn("h-full flex flex-col", className)}>
|
||||
<div className="p-4 border-b">
|
||||
<Card className={cn("h-full flex flex-col overflow-hidden", className)}>
|
||||
<div className="p-4 border-b flex-shrink-0">
|
||||
<h2 className="font-semibold text-lg">Messages</h2>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
{conversations.length} conversation{conversations.length !== 1 ? 's' : ''}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<ScrollArea className="flex-1">
|
||||
<div className="p-2 space-y-1">
|
||||
{conversations.map((conversation) => (
|
||||
<ConversationItem
|
||||
key={conversation.pubkey}
|
||||
pubkey={conversation.pubkey}
|
||||
isSelected={selectedPubkey === conversation.pubkey}
|
||||
onClick={() => onSelectConversation(conversation.pubkey)}
|
||||
lastMessage={conversation.lastMessage}
|
||||
lastActivity={conversation.lastActivity}
|
||||
hasNIP17Messages={conversation.hasNIP17Messages}
|
||||
/>
|
||||
))}
|
||||
<Tabs defaultValue="known" className="flex-1 flex flex-col min-h-0">
|
||||
<div className="px-4 pt-2 flex-shrink-0">
|
||||
<TabsList className="grid w-full grid-cols-2">
|
||||
<TabsTrigger value="known" className="text-xs">
|
||||
Active {knownConversations.length > 0 && `(${knownConversations.length})`}
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="requests" className="text-xs">
|
||||
Requests {requestConversations.length > 0 && `(${requestConversations.length})`}
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
|
||||
<TabsContent value="known" className="flex-1 mt-0 min-h-0">
|
||||
{renderConversationList(knownConversations)}
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="requests" className="flex-1 mt-0 min-h-0">
|
||||
{renderConversationList(requestConversations)}
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
</Card>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user