"use client"; import * as React from "react"; import { Plus, Trash, Pencil } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Sidebar, SidebarContent, SidebarFooter, SidebarHeader, SidebarMenu, SidebarMenuItem, SidebarMenuButton, } from "@/components/ui/sidebar"; import { useSessionContext } from "@/context/SessionContext"; export function AppSidebar() { const { sessions, currentSessionId, createNewSession, switchSession, deleteSession, renameSession, } = useSessionContext(); const [editingSessionId, setEditingSessionId] = React.useState( null ); const [newSessionName, setNewSessionName] = React.useState(""); const handleRename = (sessionId: string) => { if (newSessionName.trim()) { renameSession(sessionId, newSessionName.trim()); setEditingSessionId(null); setNewSessionName(""); } }; return ( {sessions.map((session) => ( {editingSessionId === session.id ? (
setNewSessionName(e.target.value)} onBlur={() => handleRename(session.id)} onKeyPress={(e) => e.key === "Enter" && handleRename(session.id) } className="mr-2" />
) : ( switchSession(session.id)} isActive={session.id === currentSessionId} > {session.name} )}
))}
); }