"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { api } from "@community/lib/api"; import { useAuth } from "@community/lib/auth"; import { useI18n } from "@community/lib/i18n"; import type { ConversationItem } from "@community/lib/types"; import RingNext from "@community/components/RingNext"; import { useRingSteps } from "@community/lib/rings"; function Avatar({ photo, name }: { photo?: string; name?: string }) { if (photo?.startsWith("http")) { return ( // eslint-disable-next-line @next/next/no-img-element ); } return {photo || name?.[0] || "💬"}; } export default function ChatClient() { const { user, token } = useAuth(); const { t } = useI18n(); const rings = useRingSteps(); const [items, setItems] = useState([]); const [loading, setLoading] = useState(Boolean(token)); useEffect(() => { if (!token) { setLoading(false); return; } setLoading(true); api .getConversations(token) .then(setItems) .catch(() => setItems([])) .finally(() => setLoading(false)); }, [token]); if (!user) { return (

{t.chat.loginTitle}

{t.chat.loginDesc}

{t.nav.login} {t.dating.meetAtEvents} {t.chat.goDating}
); } return (
{t.chat.tag}

{t.chat.title}

{loading &&

{t.chat.loadingList}

} {!loading && items.map((c) => ( 0 ? " unread" : ""}`} >
{c.peer?.name || t.chat.peerFallback}

{c.lastMessagePreview || t.chat.noMessages}

{c.unreadCount > 0 && {c.unreadCount}} ))} {!loading && items.length === 0 && (

{t.chat.empty}

{t.chat.goDating} {t.dating.meetAtEvents} {t.nav.community}
)}
); }