import { useState } from 'react'; import { Terminal, ChevronUp, ChevronDown } from 'lucide-react'; import { Card } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { useAutoScroll } from '@/hooks/useAutoScroll'; import { cn } from "@/lib/utils"; export interface LogEntry { log: string; timestamp?: number; // Added optional timestamp for potential sorting if needed } interface RealtimeLogsProps { logs: string[]; className?: string; } export function RealtimeLogs({ logs, className }: RealtimeLogsProps) { // Default to expanded if there are logs, or maybe collapsed to be unintrusive? // Original code: const [isExpanded, setIsExpanded] = useState(false); // Let's keep it collapsed by default as per original code to avoid clutter. const [isExpanded, setIsExpanded] = useState(false); const logsViewportRef = useAutoScroll(logs.length); const toggleExpand = () => { setIsExpanded(!isExpanded); }; return (
Real-time Logs {/* Preview last log when collapsed */} {!isExpanded && logs.length > 0 && (
{logs[logs.length - 1]}
)} {!isExpanded && logs.length === 0 && ( Waiting for logs... )}
{/* Expanded Content */}
{logs.length === 0 && Waiting for logs...} {logs.map((entry, i) => (
{entry}
))}
); }