"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Badge } from "@/components/ui/badge"; import { cn } from "@/lib/utils"; type ConversationSummary = { id: string; otherUser: { id: string; name: string; username: string | null; avatarUrl: string | null } | null; lastMessage: string | null; lastMessageAt: string; unreadCount: number; }; export function ConversationsList() { const pathname = usePathname(); const [conversations, setConversations] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { let cancelled = false; async function load() { const res = await fetch("/api/v1/conversations"); if (res.ok && !cancelled) { const data = (await res.json()) as { conversations: ConversationSummary[] }; setConversations(data.conversations); } if (!cancelled) setLoading(false); } void load(); const interval = setInterval(load, 10000); return () => { cancelled = true; clearInterval(interval); }; }, []); if (loading) return

Loading…

; if (conversations.length === 0) { return

No conversations yet. Visit a profile to say hi.

; } return (
{conversations.map((c) => ( {c.otherUser?.avatarUrl && } {(c.otherUser?.name ?? "?").slice(0, 2).toUpperCase()}

0 && "font-semibold")}> {c.otherUser?.name ?? "Unknown"}

{c.unreadCount > 0 && ( {c.unreadCount > 9 ? "9+" : c.unreadCount} )}

0 ? "text-foreground" : "text-muted-foreground")}> {c.lastMessage ?? "No messages yet"}

))}
); }