import { useT } from "../../i18n"; import type { DraftOut, RemoteDraftOut } from "../../lib/types"; function timeLabel(iso: string): string { const d = new Date(iso); const now = new Date(); if (d.toDateString() === now.toDateString()) return d.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }); return d.toLocaleDateString([], { month: "short", day: "numeric" }); } function DraftRow({ recipients, subject, preview, time, badge, onClick, }: { recipients: string; subject: string; preview: string; time: string; badge?: string; onClick: () => void; }) { return ( ); } // The Drafts folder lists local drafts (the `drafts` table) plus drafts found in // the account's IMAP Drafts folder that were created on another client. export function DraftsList({ drafts, remoteDrafts, onOpen, onOpenRemote, }: { drafts: DraftOut[]; remoteDrafts: RemoteDraftOut[]; onOpen: (draft: DraftOut) => void; onOpenRemote: (draft: RemoteDraftOut) => void; }) { const t = useT(); if (drafts.length === 0 && remoteDrafts.length === 0) { return
{t("compose.noDrafts")}
; } // Merge local + remote drafts into one list sorted by date (newest first). type Row = { key: string; date: string; recipients: string; subject: string; preview: string; badge?: string; onClick: () => void; }; const rows: Row[] = [ ...drafts.map((d) => ({ key: `l-${d.id}`, date: d.updated_at, recipients: d.payload.to.join(", ") || t("compose.noRecipient"), subject: d.payload.subject || t("compose.noSubject"), preview: d.payload.text.trim(), onClick: () => onOpen(d), })), ...remoteDrafts.map((d) => ({ key: `r-${d.message_id}`, date: d.updated_at, recipients: d.to.join(", ") || t("compose.noRecipient"), subject: d.subject || t("compose.noSubject"), preview: d.snippet.trim(), badge: t("compose.otherClient"), onClick: () => onOpenRemote(d), })), ].sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()); return (
{rows.map((row) => ( ))}
); }