import { useRef } from "react"; import { useNavigate } from "react-router"; import type { FileSummary, BodyElement, ContractPhase } from "../../lib/api"; import { markdownToBody } from "../../lib/markdown"; interface FileListProps { files: FileSummary[]; loading: boolean; onSelect: (id: string) => void; onDelete: (id: string) => void; onCreate: () => void; onUploadMarkdown?: (name: string, body: BodyElement[]) => void; } function formatDuration(seconds: number | null): string { if (seconds === null) return "-"; const mins = Math.floor(seconds / 60); const secs = Math.floor(seconds % 60); return `${mins}:${secs.toString().padStart(2, "0")}`; } function formatDate(dateStr: string): string { const date = new Date(dateStr); return date.toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric", hour: "2-digit", minute: "2-digit", }); } const phaseColors: Record = { research: "bg-purple-500/20 text-purple-400 border-purple-400/30", specify: "bg-blue-500/20 text-blue-400 border-blue-400/30", plan: "bg-cyan-500/20 text-cyan-400 border-cyan-400/30", execute: "bg-green-500/20 text-green-400 border-green-400/30", review: "bg-yellow-500/20 text-yellow-400 border-yellow-400/30", }; export function FileList({ files, loading, onSelect, onDelete, onCreate, onUploadMarkdown, }: FileListProps) { const navigate = useNavigate(); const fileInputRef = useRef(null); const handleFileUpload = (event: React.ChangeEvent) => { const file = event.target.files?.[0]; if (!file || !onUploadMarkdown) return; const reader = new FileReader(); reader.onload = (e) => { const content = e.target?.result as string; if (content) { const body = markdownToBody(content); // Use filename without extension as the name const name = file.name.replace(/\.md$/i, '') || 'Imported Document'; onUploadMarkdown(name, body); } }; reader.readAsText(file); // Reset input so the same file can be uploaded again if (fileInputRef.current) { fileInputRef.current.value = ''; } }; if (loading) { return (
Loading files...
); } return (
FILES//
{onUploadMarkdown && ( <> )}
{files.length === 0 ? (
No saved files yet. Start recording to create one.
) : (
{files.map((file) => (
)}
))}
)}
); }