import { useChatStore } from '../store/chatStore'; import { MessageSquare, Trash2, SquarePen } from 'lucide-react'; export function ConversationList() { const { conversations, currentConversationId, messages, agents, currentAgent, newConversation, switchConversation, deleteConversation, } = useChatStore(); const hasActiveChat = messages.length > 0; return (
{/* Header */}
对话历史
{/* Current active chat (unsaved) */} {hasActiveChat && !currentConversationId && (
当前对话
{messages.filter(m => m.role === 'user').length} 条消息 · {currentAgent?.name || 'ZCLAW'}
)} {/* Saved conversations */} {conversations.map((conv) => { const isActive = conv.id === currentConversationId; const msgCount = conv.messages.filter(m => m.role === 'user').length; const timeStr = formatTime(conv.updatedAt); const agentName = conv.agentId ? agents.find((agent) => agent.id === conv.agentId)?.name || conv.agentId : 'ZCLAW'; return (
switchConversation(conv.id)} className={`group flex items-center gap-3 px-3 py-3 cursor-pointer border-b border-gray-50 transition-colors ${ isActive ? 'bg-orange-50' : 'hover:bg-gray-100' }`} >
{conv.title}
{msgCount} 条消息 · {agentName} · {timeStr}
); })} {conversations.length === 0 && !hasActiveChat && (

暂无对话

发送消息开始对话

)}
); } function formatTime(date: Date): string { const now = new Date(); const d = new Date(date); const diffMs = now.getTime() - d.getTime(); const diffMin = Math.floor(diffMs / 60000); if (diffMin < 1) return '刚刚'; if (diffMin < 60) return `${diffMin} 分钟前`; const diffHr = Math.floor(diffMin / 60); if (diffHr < 24) return `${diffHr} 小时前`; const diffDay = Math.floor(diffHr / 24); if (diffDay < 7) return `${diffDay} 天前`; return `${d.getMonth() + 1}/${d.getDate()}`; }