2025-03-30 19:28:28 -03:00
|
|
|
import React from 'react';
|
|
|
|
import { formatDistanceToNow } from 'date-fns';
|
2025-03-30 16:42:51 -03:00
|
|
|
|
2025-03-30 19:28:28 -03:00
|
|
|
interface Mail {
|
|
|
|
id: string;
|
|
|
|
name: string;
|
|
|
|
subject: string;
|
|
|
|
email: string;
|
|
|
|
date: string;
|
|
|
|
text: string;
|
|
|
|
read: boolean;
|
|
|
|
labels: string[];
|
|
|
|
}
|
2025-03-30 16:42:51 -03:00
|
|
|
|
|
|
|
interface MailListProps {
|
|
|
|
items: Mail[];
|
2025-04-02 02:43:36 -03:00
|
|
|
selectedId?: string | null;
|
2025-03-30 19:28:28 -03:00
|
|
|
onSelect: (id: string) => void;
|
2025-03-30 16:42:51 -03:00
|
|
|
}
|
|
|
|
|
2025-03-30 19:28:28 -03:00
|
|
|
export function MailList({ items, selectedId, onSelect }: MailListProps) {
|
2025-03-30 16:42:51 -03:00
|
|
|
return (
|
2025-04-02 02:43:36 -03:00
|
|
|
<div className="divide-y">
|
2025-03-30 19:28:28 -03:00
|
|
|
{items.map((item) => (
|
|
|
|
<div
|
|
|
|
key={item.id}
|
|
|
|
onClick={() => onSelect(item.id)}
|
2025-04-02 02:43:36 -03:00
|
|
|
className={`p-3 cursor-pointer ${
|
|
|
|
selectedId === item.id ? 'bg-gray-100' : ''
|
|
|
|
} hover:bg-gray-50`}
|
2025-03-30 19:28:28 -03:00
|
|
|
>
|
|
|
|
<div className="flex justify-between items-start">
|
2025-04-02 02:43:36 -03:00
|
|
|
<div className="flex items-center space-x-2">
|
2025-03-30 19:28:28 -03:00
|
|
|
<div className={`w-2 h-2 rounded-full ${item.read ? 'bg-transparent' : 'bg-blue-500'}`} />
|
2025-04-02 02:43:36 -03:00
|
|
|
<h3 className="font-medium text-sm">{item.name}</h3>
|
2025-03-30 19:28:28 -03:00
|
|
|
</div>
|
2025-04-02 02:43:36 -03:00
|
|
|
<span className="text-xs text-gray-500">
|
2025-03-30 19:28:28 -03:00
|
|
|
{formatDistanceToNow(new Date(item.date), { addSuffix: true })}
|
|
|
|
</span>
|
|
|
|
</div>
|
2025-04-02 02:43:36 -03:00
|
|
|
<h4 className="font-medium text-sm mt-1">{item.subject}</h4>
|
|
|
|
<p className="text-xs text-gray-500 mt-1 truncate">
|
2025-03-30 19:28:28 -03:00
|
|
|
{item.text.substring(0, 100)}...
|
|
|
|
</p>
|
|
|
|
{item.labels.length > 0 && (
|
|
|
|
<div className="flex flex-wrap gap-1 mt-2">
|
|
|
|
{item.labels.map((label) => (
|
2025-04-02 02:43:36 -03:00
|
|
|
<span key={label} className="px-2 py-0.5 text-xs bg-gray-200 rounded-full">
|
2025-03-30 19:28:28 -03:00
|
|
|
{label}
|
|
|
|
</span>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
2025-03-30 16:42:51 -03:00
|
|
|
);
|
|
|
|
}
|