import { motion } from "framer-motion"; import { Plus, MessageSquare, Trash2, Server, Sparkles } from "lucide-react"; import { Button } from "@/components/ui/button"; import { ScrollArea } from "@/components/ui/scroll-area"; import { Conversation, AIProvider } from "@/types/chat"; import { cn } from "@/lib/utils"; interface ConversationSidebarProps { conversations: Conversation[]; activeConversationId: string | null; onSelectConversation: (id: string) => void; onNewConversation: () => void; onDeleteConversation: (id: string) => void; } const providerIcons: Record = { ollama: , openai: , }; export function ConversationSidebar({ conversations, activeConversationId, onSelectConversation, onNewConversation, onDeleteConversation, }: ConversationSidebarProps) { const groupedConversations = groupByDate(conversations); return (
{/* Header */}
{/* Conversation List */}
{Object.entries(groupedConversations).map(([group, items]) => (

{group}

{items.map((conversation) => ( ))}
))} {conversations.length === 0 && (

No conversations yet

)}
); } function groupByDate(conversations: Conversation[]): Record { const today = new Date(); const yesterday = new Date(today); yesterday.setDate(yesterday.getDate() - 1); const groups: Record = {}; conversations.forEach((conversation) => { const date = new Date(conversation.updatedAt); let group: string; if (isSameDay(date, today)) { group = "Today"; } else if (isSameDay(date, yesterday)) { group = "Yesterday"; } else { group = "Older"; } if (!groups[group]) { groups[group] = []; } groups[group].push(conversation); }); return groups; } function isSameDay(date1: Date, date2: Date): boolean { return ( date1.getFullYear() === date2.getFullYear() && date1.getMonth() === date2.getMonth() && date1.getDate() === date2.getDate() ); }