import React from 'react'; import { __ } from '@wordpress/i18n'; import '../styles/ConversationList.scss'; const ConversationList = ({ conversations, onSelect, selectedId, loadingId }) => { const formatDate = (dateString) => { const date = new Date(dateString); return date.toLocaleString(); }; const truncateMessage = (message, length = 50) => { return message.length > length ? message.substring(0, length) + '...' : message; }; // Ensure conversations is an array const conversationArray = Array.isArray(conversations) ? conversations : (conversations?.conversations || []); return (
{conversationArray.length === 0 ? (
{__( 'No previous conversations found', 'aisk-ai-chat' )}
) : ( conversationArray.map((conversation) => (
loadingId ? null : onSelect(conversation.conversation_id)} >
{formatDate(conversation.created_at)} {conversation.status}
{conversation.preview && (
{truncateMessage(conversation.preview)}
)} {loadingId === conversation.conversation_id && (
{__( 'Loading…', 'aisk-ai-chat' )}
)}
)) )}
); }; export default ConversationList;