import { useEffect, useRef, useCallback } from 'react'; import { LogEntry } from '../../api/types'; import { LogEntry as LogEntryComponent } from './LogEntry'; import { cn } from '../../utils/helpers'; interface LogStreamProps { logs: LogEntry[]; isLoading?: boolean; isLive?: boolean; autoScroll?: boolean; className?: string; maxHeight?: string; } export function LogStream({ logs, isLoading = false, isLive = false, autoScroll = true, className, maxHeight = '500px', }: LogStreamProps) { const containerRef = useRef(null); const prevLogsLength = useRef(logs.length); const scrollToBottom = useCallback(() => { if (containerRef.current) { containerRef.current.scrollTop = containerRef.current.scrollHeight; } }, []); useEffect(() => { if (autoScroll && logs.length > prevLogsLength.current) { scrollToBottom(); } prevLogsLength.current = logs.length; }, [logs.length, autoScroll, scrollToBottom]); return (
{isLoading && logs.length === 0 ? (
Загрузка логов...
) : logs.length === 0 ? (
Нет логов для отображения
) : (
{logs.map((log) => ( ))}
)} {isLive && (
Прямой эфир
)}
); } export default LogStream;