-
Notifications
You must be signed in to change notification settings - Fork 1
feat: t-timers UI #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/t-timers
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,97 @@ | ||||||||||||||||||||
| import React from 'react' | ||||||||||||||||||||
| import { RundownTTimer } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist' | ||||||||||||||||||||
| import { useTiming } from '../RundownTiming/withTiming' | ||||||||||||||||||||
| import { RundownUtils } from '../../../lib/rundown' | ||||||||||||||||||||
| import classNames from 'classnames' | ||||||||||||||||||||
| import { getCurrentTime } from '../../../lib/systemTime' | ||||||||||||||||||||
|
|
||||||||||||||||||||
| interface IProps { | ||||||||||||||||||||
| tTimers: [RundownTTimer, RundownTTimer, RundownTTimer] | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| export const RundownHeaderTimers: React.FC<IProps> = ({ tTimers }) => { | ||||||||||||||||||||
| useTiming() | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const activeTimers = tTimers.filter((t) => t.mode) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (activeTimers.length == 0) return null | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return ( | ||||||||||||||||||||
| <div className="timing__header_t-timers"> | ||||||||||||||||||||
| {activeTimers.map((timer) => ( | ||||||||||||||||||||
| <SingleTimer key={timer.index} timer={timer} /> | ||||||||||||||||||||
| ))} | ||||||||||||||||||||
| </div> | ||||||||||||||||||||
| ) | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| interface ISingleTimerProps { | ||||||||||||||||||||
| timer: RundownTTimer | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| function SingleTimer({ timer }: ISingleTimerProps) { | ||||||||||||||||||||
| const now = getCurrentTime() | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const isRunning = !!timer.state && !timer.state.paused | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const diff = calculateDiff(timer, now) | ||||||||||||||||||||
| const timeStr = RundownUtils.formatDiffToTimecode(Math.abs(diff), false, true, true, false, true) | ||||||||||||||||||||
| const parts = timeStr.split(':') | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const timerSign = diff >= 0 ? '+' : '-' | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const isCountingDown = timer.mode?.type === 'countdown' && diff < 0 && isRunning | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return ( | ||||||||||||||||||||
| <div | ||||||||||||||||||||
| className={classNames('timing__header_t-timers__timer', { | ||||||||||||||||||||
| 'timing__header_t-timers__timer__countdown': timer.mode!.type === 'countdown', | ||||||||||||||||||||
| 'timing__header_t-timers__timer__freeRun': timer.mode!.type === 'freeRun', | ||||||||||||||||||||
| 'timing__header_t-timers__timer__isRunning': isRunning, | ||||||||||||||||||||
| 'timing__header_t-timers__timer__isPaused': !isRunning, | ||||||||||||||||||||
|
Comment on lines
+47
to
+51
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need the Also can you do:
Suggested change
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's right, typescript detects it but after moving it out higher (to the rendering component) it doesn't anymore. As for the class concatenation, I would advise against it as it will make the classes un-ctrl+f-able across the codebase, and prone to unexpected breaks |
||||||||||||||||||||
| 'timing__header_t-timers__timer__isCountingDown': timer.mode!.type === 'countdown' && isCountingDown, | ||||||||||||||||||||
| 'timing__header_t-timers__timer__isCountingUp': timer.mode!.type === 'countdown' && !isCountingDown, | ||||||||||||||||||||
| 'timing__header_t-timers__timer__isComplete': | ||||||||||||||||||||
| timer.mode!.type === 'countdown' && timer.state !== null && diff <= 0, | ||||||||||||||||||||
| })} | ||||||||||||||||||||
| > | ||||||||||||||||||||
| <span className="timing__header_t-timers__timer__label">{timer.label}</span> | ||||||||||||||||||||
| <div className="timing__header_t-timers__timer__value"> | ||||||||||||||||||||
| <span className="timing__header_t-timers__timer__sign">{timerSign}</span> | ||||||||||||||||||||
| {parts.map((p, i) => ( | ||||||||||||||||||||
| <React.Fragment key={i}> | ||||||||||||||||||||
| <span | ||||||||||||||||||||
| className={classNames('timing__header_t-timers__timer__part', { | ||||||||||||||||||||
| 'timing__header_t-timers__timer__part--dimmed': Math.abs(diff) < [3600000, 60000, 1][i], | ||||||||||||||||||||
| })} | ||||||||||||||||||||
| > | ||||||||||||||||||||
| {p} | ||||||||||||||||||||
| </span> | ||||||||||||||||||||
| {i < parts.length - 1 && <span className="timing__header_t-timers__timer__separator">:</span>} | ||||||||||||||||||||
| </React.Fragment> | ||||||||||||||||||||
| ))} | ||||||||||||||||||||
| </div> | ||||||||||||||||||||
| </div> | ||||||||||||||||||||
| ) | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| function calculateDiff(timer: RundownTTimer, now: number): number { | ||||||||||||||||||||
| if (!timer.state) { | ||||||||||||||||||||
| return 0 | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Get current time: either frozen duration or calculated from zeroTime | ||||||||||||||||||||
| const currentTime = timer.state.paused ? timer.state.duration : timer.state.zeroTime - now | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Free run counts up, so negate to get positive elapsed time | ||||||||||||||||||||
| if (timer.mode?.type === 'freeRun') { | ||||||||||||||||||||
| return -currentTime | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // Apply stopAtZero if configured | ||||||||||||||||||||
| if (timer.mode?.stopAtZero && currentTime < 0) { | ||||||||||||||||||||
| return 0 | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return currentTime | ||||||||||||||||||||
| } | ||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.