"use client"; import { useState } from "react"; import { useAppStore } from "@/store/app-store"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Plus, MessageSquare, Archive, Trash2, MoreVertical, Search, ChevronLeft, ArchiveRestore, } from "lucide-react"; import { cn } from "@/lib/utils"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, DropdownMenuSeparator, } from "@/components/ui/dropdown-menu"; import { Badge } from "@/components/ui/badge"; export function ChatHistory() { const { chatSessions, currentProject, currentChatSession, chatHistoryOpen, createChatSession, setCurrentChatSession, archiveChatSession, unarchiveChatSession, deleteChatSession, setChatHistoryOpen, } = useAppStore(); const [searchQuery, setSearchQuery] = useState(""); const [showArchived, setShowArchived] = useState(false); if (!currentProject) { return null; } // Filter sessions for current project const projectSessions = chatSessions.filter( (session) => session.projectId === currentProject.id ); // Filter by search query and archived status const filteredSessions = projectSessions.filter((session) => { const matchesSearch = session.title .toLowerCase() .includes(searchQuery.toLowerCase()); const matchesArchivedStatus = showArchived ? session.archived : !session.archived; return matchesSearch && matchesArchivedStatus; }); // Sort by most recently updated const sortedSessions = filteredSessions.sort( (a, b) => new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime() ); const handleCreateNewChat = () => { createChatSession(); }; const handleSelectSession = (session: any) => { setCurrentChatSession(session); }; const handleArchiveSession = (sessionId: string, e: React.MouseEvent) => { e.stopPropagation(); archiveChatSession(sessionId); }; const handleUnarchiveSession = (sessionId: string, e: React.MouseEvent) => { e.stopPropagation(); unarchiveChatSession(sessionId); }; const handleDeleteSession = (sessionId: string, e: React.MouseEvent) => { e.stopPropagation(); if (confirm("Are you sure you want to delete this chat session?")) { deleteChatSession(sessionId); } }; return (
{session.messages.length} messages
{new Date(session.updatedAt).toLocaleDateString()}