mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-16 04:43:35 +00:00
refactor: extract countdown data to hook
This commit is contained in:
committed by
Carlos Valente
parent
20ee391525
commit
f23adfa45c
@@ -1,7 +1,6 @@
|
||||
import { EntryId, OntimeEvent, Playback, TimerType } from 'ontime-types';
|
||||
import { EntryId, MaybeNumber, OntimeEvent, Playback, TimerType } from 'ontime-types';
|
||||
import { dayInMs } from 'ontime-utils';
|
||||
|
||||
import { ViewExtendedTimer } from '../../common/models/TimeManager.type';
|
||||
import { getFormattedTimer } from '../../features/viewers/common/viewUtils';
|
||||
import type { TranslationKey } from '../../translation/TranslationProvider';
|
||||
|
||||
@@ -46,7 +45,9 @@ export const timerProgress: TimerMessage = {
|
||||
* TODO: get timer data granularly
|
||||
*/
|
||||
export function getSubscriptionDisplayData(
|
||||
time: ViewExtendedTimer,
|
||||
current: MaybeNumber,
|
||||
playback: Playback,
|
||||
clock: number,
|
||||
subscribedEvent: OntimeEvent,
|
||||
selectedId: EntryId | null,
|
||||
offset: number,
|
||||
@@ -58,7 +59,7 @@ export function getSubscriptionDisplayData(
|
||||
|
||||
if (selectedId === subscribedEvent.id) {
|
||||
// 1. An event that is loaded but not running is {'due': <countdown | overtime>}
|
||||
if (time.playback === Playback.Armed) {
|
||||
if (playback === Playback.Armed) {
|
||||
// if we are following the event, but it is not running, we show the scheduled start
|
||||
return {
|
||||
status: 'due',
|
||||
@@ -74,7 +75,7 @@ export function getSubscriptionDisplayData(
|
||||
// 2. An event with a time-to-start lower than 0 is {'due': <countdown | scheduledStart>}, show the running timer
|
||||
return {
|
||||
status: 'live',
|
||||
timer: getFormattedTimer(time.current, TimerType.CountDown, minutesString, subscriptionTimerDisplayOptions),
|
||||
timer: getFormattedTimer(current, TimerType.CountDown, minutesString, subscriptionTimerDisplayOptions),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -89,7 +90,7 @@ export function getSubscriptionDisplayData(
|
||||
return {
|
||||
status: 'future',
|
||||
timer: getFormattedTimer(
|
||||
subscribedEvent.timeStart + dayOffset - time.clock - offsetAndDelay,
|
||||
subscribedEvent.timeStart + dayOffset - clock - offsetAndDelay,
|
||||
TimerType.CountDown,
|
||||
minutesString,
|
||||
subscriptionTimerDisplayOptions,
|
||||
@@ -113,11 +114,11 @@ export function getSubscriptionDisplayData(
|
||||
|
||||
// 5. if event is in future, we count to the scheduled start
|
||||
// TODO: get time until
|
||||
if (time.clock < subscribedEvent.timeStart) {
|
||||
if (clock < subscribedEvent.timeStart) {
|
||||
return {
|
||||
status: 'future',
|
||||
timer: getFormattedTimer(
|
||||
subscribedEvent.timeStart - time.clock - offsetAndDelay,
|
||||
subscribedEvent.timeStart - clock - offsetAndDelay,
|
||||
TimerType.CountDown,
|
||||
minutesString,
|
||||
subscriptionTimerDisplayOptions,
|
||||
@@ -127,7 +128,7 @@ export function getSubscriptionDisplayData(
|
||||
|
||||
// 6. if event has ended, we show the scheduled end
|
||||
// TODO: get the time from the reporter
|
||||
if (time.clock > subscribedEvent.timeEnd) {
|
||||
if (clock > subscribedEvent.timeEnd) {
|
||||
return {
|
||||
status: 'done',
|
||||
timer: getFormattedTimer(
|
||||
|
||||
Reference in New Issue
Block a user