"use client"; import { useEffect, useRef, useMemo, useState } from "react"; import { CapturedEvent } from "@/types"; import { DeepgramEventItem, FluxEventItem, SpeechmaticsEventItem } from "./events"; interface EventListProps { events: CapturedEvent[]; currentTime: number; onSeek: (time: number) => void; provider: string; } function formatTime(seconds: number): string { const mins = Math.floor(seconds / 60); const secs = Math.floor(seconds % 60); const ms = Math.floor((seconds % 1) * 100); return `${mins}:${secs.toString().padStart(2, "0")}.${ms.toString().padStart(2, "0")}`; } function getEventItemComponent(provider: string) { if (provider === "deepgram-flux") { return FluxEventItem; } if (provider === "speechmatics") { return SpeechmaticsEventItem; } // Default to Deepgram Nova return DeepgramEventItem; } export default function EventList({ events, currentTime, onSeek, provider, }: EventListProps) { const containerRef = useRef(null); const [expandedEvents, setExpandedEvents] = useState>(new Set()); const [autoScroll, setAutoScroll] = useState(true); const EventItemComponent = getEventItemComponent(provider); // Find the current event index based on time const currentEventIndex = useMemo(() => { for (let i = events.length - 1; i >= 0; i--) { if (events[i].timestamp <= currentTime) { return i; } } return -1; }, [events, currentTime]); // Auto-scroll to current event useEffect(() => { if (!autoScroll || currentEventIndex < 0) return; const container = containerRef.current; if (!container) return; const eventElement = container.querySelector(`[data-index="${currentEventIndex}"]`); if (eventElement) { eventElement.scrollIntoView({ behavior: "smooth", block: "center" }); } }, [currentEventIndex, autoScroll]); const toggleExpand = (index: number) => { setExpandedEvents((prev) => { const next = new Set(prev); if (next.has(index)) { next.delete(index); } else { next.add(index); } return next; }); }; return (
Events ({events.length})
{events.map((event, index) => { const isCurrent = index === currentEventIndex; const isExpanded = expandedEvents.has(index); return (
onSeek(event.timestamp)} >
{/* Current indicator */}
{isCurrent ? (
) : (
)}
{/* Timestamp */} {formatTime(event.timestamp)} {/* Provider-specific event item */} toggleExpand(index)} />
); })}
); }