import { OntimeEvent } from 'ontime-types'; import { MILLIS_PER_MINUTE } from 'ontime-utils'; import { useExpectedStartData } from '../../common/hooks/useSocket'; import { ExtendedEntry } from '../../common/utils/rundownMetadata'; import { formatDuration, getExpectedTimesFromExtendedEvent } from '../../common/utils/time'; import { useTranslation } from '../../translation/TranslationProvider'; import TimelineSection from './timeline-section/TimelineSection'; interface TimelineSectionsProps { now: ExtendedEntry | null; next: ExtendedEntry | null; followedBy: ExtendedEntry | null; } export default function TimelineSections({ now, next, followedBy }: TimelineSectionsProps) { const { getLocalizedString } = useTranslation(); const state = useExpectedStartData(); // gather card data const titleNow = now?.title ?? '-'; const dueText = getLocalizedString('timeline.due').toUpperCase(); const nextText = next !== null ? next.title : '-'; const followedByText = followedBy !== null ? followedBy.title : '-'; let nextStatus: string | undefined; let followedByStatus: string | undefined; if (next !== null) { const { timeToStart } = getExpectedTimesFromExtendedEvent(next, state); if (timeToStart <= 0) { nextStatus = dueText; } else { nextStatus = formatDuration(timeToStart, timeToStart > MILLIS_PER_MINUTE * 2); } } if (followedBy !== null) { const { timeToStart } = getExpectedTimesFromExtendedEvent(followedBy, state); if (timeToStart <= 0) { followedByStatus = dueText; } else { followedByStatus = formatDuration(timeToStart, timeToStart > MILLIS_PER_MINUTE * 2); } } return (
); }