refactor: allow overriding timer type in view

This commit is contained in:
Carlos Valente
2025-01-24 11:29:28 +01:00
committed by Carlos Valente
parent 78c2bd79b5
commit d58335d1a1
4 changed files with 43 additions and 11 deletions
@@ -7,11 +7,17 @@ import { formatTime } from '../../../common/utils/time';
type TimerTypeParams = Pick<ViewExtendedTimer, 'countToEnd' | 'timerType' | 'current' | 'elapsed' | 'clock'>;
export function getTimerByType(freezeEnd: boolean, timerObject?: TimerTypeParams): number | null {
export function getTimerByType(
freezeEnd: boolean,
timerObject?: TimerTypeParams,
timerTypeOverride?: TimerType,
): number | null {
if (!timerObject) {
return null;
}
const viewTimerType = timerTypeOverride ?? timerObject.timerType;
if (timerObject.countToEnd) {
if (timerObject.current === null) {
return null;
@@ -19,7 +25,7 @@ export function getTimerByType(freezeEnd: boolean, timerObject?: TimerTypeParams
return freezeEnd ? Math.max(timerObject.current, 0) : timerObject.current;
}
switch (timerObject.timerType) {
switch (viewTimerType) {
case TimerType.CountDown:
if (timerObject.current === null) {
return null;
@@ -31,10 +37,8 @@ export function getTimerByType(freezeEnd: boolean, timerObject?: TimerTypeParams
return timerObject.clock;
case TimerType.None:
return null;
default: {
const exhaustiveCheck: never = timerObject.timerType;
return exhaustiveCheck;
}
default:
return null;
}
}