import { useEffect, useState } from "react"; import { useConversationStore } from "../stores/conversation.ts"; import { useAuthStore } from "../stores/auth.ts"; import { NewConversationModal } from "./NewConversationModal.tsx"; function otherMemberName(conv: { members: { id: string; username: string }[] }, currentUserId: string) { const other = conv.members.find((m) => m.id !== currentUserId); return other?.username || "unknown"; } export function ConversationList() { const conversations = useConversationStore((s) => s.conversations); const activeId = useConversationStore((s) => s.activeConversationId); const fetchConversations = useConversationStore((s) => s.fetchConversations); const setActive = useConversationStore((s) => s.setActiveConversation); const currentUser = useAuthStore((s) => s.user); const [showNew, setShowNew] = useState(false); useEffect(() => { fetchConversations(); }, [fetchConversations]); return (
[DIRECT MESSAGES]
{conversations.length === 0 && (

[no conversations]

)} {conversations.map((conv) => { const name = conv.type === "group_dm" ? conv.name || conv.members.map((m) => m.username).join(", ") : otherMemberName(conv, currentUser?.id || ""); return ( ); })}
{showNew && setShowNew(false)} />}
); }