import React, { useEffect, useState } from 'react' import { EventError, EventRecord } from '../..' import { JSONView } from '../JSONView' import { ErrorDescription, ErrorHeading, ErrorMessage, JSONViewContainer, SnapshotIcon, SnapshotItem, SnapshotList, SnapshotPreview, TimelineContainer } from './style' export type EventTimelineProps = { timeline: EventRecord['timeline'] } export const EventTimeline = ({ timeline }: EventTimelineProps) => { const [selectedSnapshotIndex, setSelectedSnapshotIndex] = useState() const activeSnapshot = timeline.at(selectedSnapshotIndex || 0) useEffect(() => setSelectedSnapshotIndex(undefined), [activeSnapshot.id]) return ( {timeline.map((snapshot, i) => ( setSelectedSnapshotIndex(i)}> ))} {'type' in activeSnapshot && (activeSnapshot as EventError).type === 'error' && ( {(activeSnapshot as EventError).message} {activeSnapshot.description && ( {(activeSnapshot as EventError).description} )} )} ) }