import React from "react"; import { Link } from "react-router-dom"; import type { ChatThread } from "./types"; import { useI18n } from "../i18n"; function formatTime(value?: number | null) { if (!value) return ""; return new Date(value).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }); } export default function ChatList({ threads, basePath, unreadIds, }: { threads: ChatThread[]; basePath: string; unreadIds?: Set; }) { const { t } = useI18n(); return (
{threads.map((thread) => { const last = thread.lastMessage; const preview = last?.body ?? t("chat.noMessages"); const path = `${basePath}/${thread.id}`; const isUnread = unreadIds?.has(thread.id); return (
{thread.kind === "global" ? "#" : thread.name.charAt(0).toUpperCase()}
{thread.name}
{formatTime(last?.createdAt)} {isUnread &&

{preview}

{thread.kind === "global" ? t("chat.global") : thread.kind === "direct" ? t("chat.direct") : t("chat.group")}
); })}
); }