refactor: show countdown if less than 10 min from start

This commit is contained in:
Carlos Valente
2025-11-02 14:35:23 +01:00
committed by Carlos Valente
parent 9f2db10548
commit 50599eccd2
4 changed files with 86 additions and 59 deletions
@@ -1,9 +1,8 @@
import { EntryId, MaybeNumber, OffsetMode, OntimeEntry, OntimeEvent, OntimeReport, Playback } from 'ontime-types';
import { getExpectedStart, MILLIS_PER_MINUTE, removeSeconds } from 'ontime-utils';
import { getExpectedStart, MILLIS_PER_MINUTE, millisToString, removeLeadingZero } from 'ontime-utils';
import { useCountdownSocket } from '../../common/hooks/useSocket';
import { ExtendedEntry } from '../../common/utils/rundownMetadata';
import { timerPlaceholderMin } from '../../common/utils/styleUtils';
import { formatDuration, formatTime } from '../../common/utils/time';
import { type TranslationKey, useTranslation } from '../../translation/TranslationProvider';
@@ -36,23 +35,6 @@ export const timerProgress: TimerMessage = {
done: 'countdown.ended',
};
export function getFormattedTime(
value: MaybeNumber,
status: ProgressStatus,
minText: string,
secText: string,
dueText: string,
) {
if (value === null) return timerPlaceholderMin;
if (status === 'future' || status === 'live') {
if (value <= 0) return dueText.toUpperCase();
return formatDuration(value, value > MILLIS_PER_MINUTE * 2)
.replace('m', `${minText} `)
.replace('s', secText);
}
return removeSeconds(formatTime(value));
}
/**
* Returns a parsed timer and relevant status message
* Handles events in different days but disregards whether an event has actually played
@@ -65,7 +47,11 @@ export function useSubscriptionDisplayData(
const bigDuration = (value: number) => {
if (value <= 0) return getLocalizedString('countdown.overtime').toUpperCase();
return formatDuration(value, value > MILLIS_PER_MINUTE * 2)
if (value < MILLIS_PER_MINUTE * 10) {
return removeLeadingZero(millisToString(value));
}
return formatDuration(value, value > MILLIS_PER_MINUTE * 10)
.replace('m', `${getLocalizedString('common.minutes')} `)
.replace('s', getLocalizedString('common.seconds'));
};
@@ -90,7 +76,7 @@ export function useSubscriptionDisplayData(
return {
status: 'pending',
statusDisplay: getLocalizedString(timerProgress['pending']),
timeDisplay: ' ',
timeDisplay: ' ',
};
}
@@ -31,7 +31,7 @@ export default function TimelineSections({ now, next, followedBy }: TimelineSect
if (timeToStart <= 0) {
nextStatus = dueText;
} else {
nextStatus = formatDuration(timeToStart, timeToStart > MILLIS_PER_MINUTE * 2);
nextStatus = formatDuration(timeToStart, timeToStart > MILLIS_PER_MINUTE * 10);
}
}
@@ -40,7 +40,7 @@ export default function TimelineSections({ now, next, followedBy }: TimelineSect
if (timeToStart <= 0) {
followedByStatus = dueText;
} else {
followedByStatus = formatDuration(timeToStart, timeToStart > MILLIS_PER_MINUTE * 2);
followedByStatus = formatDuration(timeToStart, timeToStart > MILLIS_PER_MINUTE * 10);
}
}
@@ -82,7 +82,7 @@ export function getStatusLabel(timeToStart: number, status: ProgressStatus): str
return 'pending';
}
return formatDuration(timeToStart, timeToStart > MILLIS_PER_MINUTE * 2);
return formatDuration(timeToStart, timeToStart > MILLIS_PER_MINUTE * 10);
}
interface ScopedRundownData {