import { MaybeNumber, Playback, TimerPhase } from 'ontime-types'; import { millisToString } from 'ontime-utils'; import { PropsWithChildren } from 'react'; import AppLink from '../../../../common/components/link/app-link/AppLink'; import Tooltip from '../../../../common/components/tooltip/Tooltip'; import useReport from '../../../../common/hooks-query/useReport'; import { useTimerProgress } from '../../../../common/hooks/useSocket'; import { cx } from '../../../../common/utils/styleUtils'; import { formatDuration, normaliseWallClock } from '../../../../common/utils/time'; import TimerDisplay from '../timer-display/TimerDisplay'; import style from './PlaybackTimer.module.scss'; function resolveAddedTimeLabel(addedTime: number) { if (addedTime > 0) { return `Added ${formatDuration(addedTime, false)}`; } if (addedTime < 0) { return `Removed ${formatDuration(Math.abs(addedTime), false)}`; } return ''; } export default function PlaybackTimer({ children }: PropsWithChildren) { 'use memo'; const timer = useTimerProgress(); const isRolling = timer.playback === Playback.Roll; const isWaiting = timer.phase === TimerPhase.Pending; const isOvertime = timer.phase === TimerPhase.Overtime; const hasAddedTime = Boolean(timer.addedTime); const rollLabel = isRolling ? 'Roll mode active' : ''; const addedTimeLabel = resolveAddedTimeLabel(timer.addedTime); return (
} className={style.indicatorRoll} data-active={isRolling} />
} className={style.indicatorDelay} data-active={hasAddedTime} />
{isWaiting ? ( Roll: Countdown to start ) : ( )}
{children}
); } interface RunningStatusProps { startedAt: MaybeNumber; expectedFinish: MaybeNumber; isStopped: boolean; isCountToEnd: boolean; isOvertime: boolean; } function RunningStatus({ startedAt, expectedFinish, isStopped, isCountToEnd, isOvertime }: RunningStatusProps) { if (isStopped) { return ; } const started = millisToString(startedAt); const finish = millisToString(expectedFinish === null ? null : normaliseWallClock(expectedFinish)); return ( <> Started at {started} {isCountToEnd ? 'Scheduled end' : 'Expected end'} {finish} ); } function StoppedStatus() { const { data } = useReport(); const hasReport = Object.keys(data).length > 0; if (hasReport) { return Go to report management; } return null; }