"use client"; import { useMemo } from "react"; import { CapturedEvent } from "@/types"; interface EventTimelineProps { events: CapturedEvent[]; duration: number; currentTime: number; onSeek: (time: number) => void; } const EVENT_COLORS: Record = { Results: "bg-blue-500", TurnInfo: "bg-green-500", AddTranscript: "bg-purple-500", Connected: "bg-yellow-500", RecognitionStarted: "bg-yellow-500", EndOfTranscript: "bg-red-500", Metadata: "bg-gray-500", Error: "bg-red-600", default: "bg-zinc-400", }; function formatTime(seconds: number): string { const mins = Math.floor(seconds / 60); const secs = Math.floor(seconds % 60); return `${mins}:${secs.toString().padStart(2, "0")}`; } export default function EventTimeline({ events, duration, currentTime, onSeek, }: EventTimelineProps) { const timeMarkers = useMemo(() => { const markers: number[] = []; const interval = Math.ceil(duration / 6); for (let i = 0; i <= duration; i += interval) { markers.push(i); } if (markers[markers.length - 1] !== Math.floor(duration)) { markers.push(Math.floor(duration)); } return markers; }, [duration]); const handleClick = (e: React.MouseEvent) => { const rect = e.currentTarget.getBoundingClientRect(); const x = e.clientX - rect.left; const percent = x / rect.width; const time = percent * duration; onSeek(Math.max(0, Math.min(time, duration))); }; const progressPercent = (currentTime / duration) * 100; return (
Event Timeline
{/* Progress indicator */}
{/* Current time indicator */}
{/* Event markers */}
{events.map((event, index) => { const leftPercent = Math.min((event.timestamp / duration) * 100, 100); const colorClass = EVENT_COLORS[event.event_type] || EVENT_COLORS.default; return (
); })}
{/* Time markers */}
{timeMarkers.map((time, index) => ( {formatTime(time)} ))}
{/* Legend */}
{Object.entries(EVENT_COLORS) .filter(([key]) => key !== "default") .slice(0, 6) .map(([eventType, colorClass]) => (
{eventType}
))}
); }