diff --git a/web/src/components/TimelineSummary.jsx b/web/src/components/TimelineSummary.jsx index 829197c91..7947406c8 100644 --- a/web/src/components/TimelineSummary.jsx +++ b/web/src/components/TimelineSummary.jsx @@ -9,9 +9,11 @@ import { Zone } from '../icons/Zone'; import { useState } from 'preact/hooks'; import { useApiHost } from '../api'; import Button from './Button'; +import VideoPlayer from './VideoPlayer'; export default function TimelineSummary({ event }) { const apiHost = useApiHost(); + const eventDuration = event.end_time - event.start_time; const { data: eventTimeline } = useSWR([ 'timeline', { @@ -23,6 +25,16 @@ export default function TimelineSummary({ event }) { const [timeIndex, setTimeIndex] = useState(0); + const onSelectMoment = async (index) => { + setTimeIndex(index); + + if (this.player) { + const videoOffset = this.player.duration() - eventDuration; + const startTime = videoOffset + (eventTimeline[index].timestamp - event.start_time); + this.player.currentTime(startTime); + } + }; + if (!eventTimeline || !config) { return ; } @@ -38,7 +50,7 @@ export default function TimelineSummary({ event }) { type="text" color={index == timeIndex ? 'blue' : 'gray'} aria-label={getTimelineItemDescription(config, item, event)} - onClick={() => setTimeIndex(index)} + onClick={() => onSelectMoment(index)} > {item.class_type == 'visible' ? : } @@ -48,7 +60,7 @@ export default function TimelineSummary({ event }) { type="text" color={index == timeIndex ? 'blue' : 'gray'} aria-label={getTimelineItemDescription(config, item, event)} - onClick={() => setTimeIndex(index)} + onClick={() => onSelectMoment(index)} > @@ -59,12 +71,25 @@ export default function TimelineSummary({ event }) {
{getTimelineItemDescription(config, eventTimeline[timeIndex], event)} -
- -
+ { + this.player = player; + }} + onDispose={() => { + this.player = null; + }} + />
);