|
| 1 | +import React from 'react' |
| 2 | +import { useTranslation } from 'react-i18next' |
| 3 | +import Moment from 'react-moment' |
| 4 | +import { getCurrentTime } from '../../../lib/systemTime.js' |
| 5 | +import { RundownUtils } from '../../../lib/rundown.js' |
| 6 | +import { useTiming } from './withTiming.js' |
| 7 | +import ClassNames from 'classnames' |
| 8 | +import { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist' |
| 9 | +import { getPlaylistTimingDiff } from '../../../lib/rundownTiming.js' |
| 10 | +import { isLoopRunning } from '../../../lib/RundownResolver.js' |
| 11 | + |
| 12 | +interface IEndTimingProps { |
| 13 | + rundownPlaylist: DBRundownPlaylist |
| 14 | + loop?: boolean |
| 15 | + expectedStart?: number |
| 16 | + expectedDuration?: number |
| 17 | + expectedEnd?: number |
| 18 | + endLabel?: string |
| 19 | + hidePlannedEndLabel?: boolean |
| 20 | + hideDiffLabel?: boolean |
| 21 | + hidePlannedEnd?: boolean |
| 22 | + hideCountdown?: boolean |
| 23 | + hideDiff?: boolean |
| 24 | +} |
| 25 | + |
| 26 | +export function PlaylistEndTimingV2({ |
| 27 | + rundownPlaylist, |
| 28 | + loop, |
| 29 | + expectedStart, |
| 30 | + expectedDuration, |
| 31 | + expectedEnd, |
| 32 | + endLabel, |
| 33 | + hidePlannedEndLabel, |
| 34 | + hideDiffLabel, |
| 35 | + hidePlannedEnd, |
| 36 | + hideCountdown, |
| 37 | + hideDiff, |
| 38 | +}: IEndTimingProps): JSX.Element { |
| 39 | + const { t } = useTranslation() |
| 40 | + |
| 41 | + const timingDurations = useTiming() |
| 42 | + |
| 43 | + const overUnderClock = getPlaylistTimingDiff(rundownPlaylist, timingDurations) ?? 0 |
| 44 | + const now = timingDurations.currentTime ?? getCurrentTime() |
| 45 | + |
| 46 | + return ( |
| 47 | + <React.Fragment> |
| 48 | + {!hideDiff ? ( |
| 49 | + timingDurations ? ( |
| 50 | + <span |
| 51 | + className={ClassNames('timing-clock heavy-light ', { |
| 52 | + heavy: overUnderClock < 0, |
| 53 | + light: overUnderClock >= 0, |
| 54 | + })} |
| 55 | + role="timer" |
| 56 | + > |
| 57 | + {!hideDiffLabel && ( |
| 58 | + <span className="timing-clock-label center">{overUnderClock < 0 ? t('Under') : t('Over')}</span> |
| 59 | + )} |
| 60 | + {RundownUtils.formatDiffToTimecode(overUnderClock, true, false, true, true, true, undefined, true, true)} |
| 61 | + </span> |
| 62 | + ) : null |
| 63 | + ) : null} |
| 64 | + |
| 65 | + {!loop && |
| 66 | + !hideCountdown && |
| 67 | + (expectedEnd ? ( |
| 68 | + <span className="timing-clock countdown plan-end" role="timer"> |
| 69 | + {RundownUtils.formatDiffToTimecode(now - expectedEnd, true, true, true)} |
| 70 | + </span> |
| 71 | + ) : expectedStart && expectedDuration ? ( |
| 72 | + <span className="timing-clock countdown plan-end" role="timer"> |
| 73 | + {RundownUtils.formatDiffToTimecode(getCurrentTime() - (expectedStart + expectedDuration), true, true, true)} |
| 74 | + </span> |
| 75 | + ) : null)} |
| 76 | + |
| 77 | + {!hidePlannedEnd ? ( |
| 78 | + expectedEnd ? ( |
| 79 | + !rundownPlaylist.startedPlayback ? ( |
| 80 | + <span className="timing-clock plan-end visual-last-child" role="timer"> |
| 81 | + {!hidePlannedEndLabel && <span className="timing-clock-label right">{endLabel ?? t('Planned End')}</span>} |
| 82 | + <Moment interval={0} format="HH:mm:ss" date={expectedEnd} /> |
| 83 | + </span> |
| 84 | + ) : ( |
| 85 | + <span className="timing-clock plan-end visual-last-child" role="timer"> |
| 86 | + {!hidePlannedEndLabel && ( |
| 87 | + <span className="timing-clock-label right">{endLabel ?? t('Expected End')}</span> |
| 88 | + )} |
| 89 | + <Moment interval={0} format="HH:mm:ss" date={expectedEnd} /> |
| 90 | + </span> |
| 91 | + ) |
| 92 | + ) : timingDurations ? ( |
| 93 | + isLoopRunning(rundownPlaylist) ? ( |
| 94 | + timingDurations.partCountdown && rundownPlaylist.activationId && rundownPlaylist.currentPartInfo ? ( |
| 95 | + <span className="timing-clock plan-end visual-last-child" role="timer"> |
| 96 | + {!hidePlannedEndLabel && <span className="timing-clock-label right">{t('Next Loop at')}</span>} |
| 97 | + <Moment |
| 98 | + interval={0} |
| 99 | + format="HH:mm:ss" |
| 100 | + date={now + (timingDurations.partCountdown[Object.keys(timingDurations.partCountdown)[0]] || 0)} |
| 101 | + /> |
| 102 | + </span> |
| 103 | + ) : null |
| 104 | + ) : ( |
| 105 | + <span className="timing-clock plan-end visual-last-child" role="timer"> |
| 106 | + {!hidePlannedEndLabel && ( |
| 107 | + <span className="timing-clock-label right">{endLabel ?? t('Planned End At')}</span> |
| 108 | + )} |
| 109 | + <span className="planned-end-time"> |
| 110 | + <Moment |
| 111 | + interval={0} |
| 112 | + format="HH:mm:ss" |
| 113 | + date={(expectedStart || now) + (timingDurations.remainingPlaylistDuration || 0)} |
| 114 | + /> |
| 115 | + </span> |
| 116 | + </span> |
| 117 | + ) |
| 118 | + ) : null |
| 119 | + ) : null} |
| 120 | + </React.Fragment> |
| 121 | + ) |
| 122 | +} |
0 commit comments