/** * Context Document Card Component * * Displays individual context documents with preview and actions */ import React from "react"; import { Card, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Trash2, FileText, Edit } from "lucide-react"; import { ContextDocument } from "@/types/context"; import { shouldRenderAsMarkdown } from "@/lib/markdown-utils"; import ReactMarkdown from "react-markdown"; interface ContextDocumentCardProps { document: ContextDocument; onDelete: () => void; onViewEdit: () => void; } export function ContextDocumentCard({ document, onDelete, onViewEdit, }: ContextDocumentCardProps) { const formatDate = (dateString: string) => { return new Date(dateString).toLocaleDateString("en-US", { year: "numeric", month: "short", day: "numeric", hour: "2-digit", minute: "2-digit", }); }; const getPreviewContent = (content: string, maxLength: number = 150) => { if (content.length <= maxLength) return content; return content.substring(0, maxLength) + "..."; }; return (
{document.title}
{/* Action buttons in top right */}
{formatDate(document.created_at)} {/* Document metadata */} Type: {document.document_type.replace(/_/g, " ")} {/* Character count */}
{document.content.length.toLocaleString()} chars
{/* Content preview */}
{shouldRenderAsMarkdown(document.content, document.file_name) ? (
{getPreviewContent(document.content, 200)}
) : (
{getPreviewContent(document.content)}
)}
); }