import { useRef, useEffect, useState } from "react"; import { CheckCircle2, ChevronDown, ChevronRight, Circle, ListChecks, Loader2, } from "lucide-react"; import type { TodoItem } from "@/lib/agents/types"; interface TodoListProps { todos: TodoItem[]; className?: string; runActive?: boolean; } function StatusIcon({ status }: { status: TodoItem["status"] }) { switch (status) { case "pending": return ; case "in_progress": return ; case "completed": return ; } } const MAX_HEIGHT = 160; export function TodoList({ todos, className = "", runActive = false }: TodoListProps) { const [collapsed, setCollapsed] = useState(false); const scrollRef = useRef(null); const prevRunActiveRef = useRef(runActive); useEffect(() => { if (prevRunActiveRef.current && !runActive) { setCollapsed(true); } prevRunActiveRef.current = runActive; }, [runActive]); useEffect(() => { const el = scrollRef.current; if (!el) return; const firstActive = todos.findIndex((t) => t.status === "in_progress"); const targetIndex = firstActive !== -1 ? firstActive : todos.length - 1; const targetEl = el.children[targetIndex] as HTMLElement | undefined; targetEl?.scrollIntoView({ block: "nearest", behavior: "smooth" }); }, [todos]); if (todos.length === 0) return null; const completed = todos.filter((t) => t.status === "completed").length; return (
{!collapsed && (
{todos.map((todo, index) => (
{index + 1}. {todo.content}
))}
)}
); }