mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-20 22:49:18 +00:00
refactor: simplify client logic on timer phases
This commit is contained in:
committed by
Carlos Valente
parent
fd2eee32aa
commit
f75f45b19a
@@ -1,4 +1,4 @@
|
|||||||
import { MaybeNumber, Playback, TimerType } from 'ontime-types';
|
import { MaybeNumber, Playback, TimerPhase, TimerType } from 'ontime-types';
|
||||||
|
|
||||||
// first set extends TimerState
|
// first set extends TimerState
|
||||||
export type ViewExtendedTimer = {
|
export type ViewExtendedTimer = {
|
||||||
@@ -8,12 +8,11 @@ export type ViewExtendedTimer = {
|
|||||||
elapsed: MaybeNumber;
|
elapsed: MaybeNumber;
|
||||||
expectedFinish: MaybeNumber;
|
expectedFinish: MaybeNumber;
|
||||||
finishedAt: MaybeNumber;
|
finishedAt: MaybeNumber;
|
||||||
|
phase: TimerPhase;
|
||||||
playback: Playback;
|
playback: Playback;
|
||||||
secondaryTimer: MaybeNumber;
|
secondaryTimer: MaybeNumber;
|
||||||
startedAt: MaybeNumber;
|
startedAt: MaybeNumber;
|
||||||
|
|
||||||
clock: number;
|
clock: number;
|
||||||
timeDanger: MaybeNumber;
|
|
||||||
timeWarning: MaybeNumber;
|
|
||||||
timerType: TimerType;
|
timerType: TimerType;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,4 +17,10 @@ declare global {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare module 'react' {
|
||||||
|
interface CSSProperties {
|
||||||
|
[key: `--${string}`]: string | number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default {};
|
export default {};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { PropsWithChildren } from 'react';
|
import { PropsWithChildren } from 'react';
|
||||||
import { Tooltip } from '@chakra-ui/react';
|
import { Tooltip } from '@chakra-ui/react';
|
||||||
import { Playback } from 'ontime-types';
|
import { Playback, TimerPhase } from 'ontime-types';
|
||||||
import { dayInMs, millisToMinutes, millisToSeconds, millisToString } from 'ontime-utils';
|
import { dayInMs, millisToMinutes, millisToSeconds, millisToString } from 'ontime-utils';
|
||||||
|
|
||||||
import { useTimer } from '../../../../common/hooks/useSocket';
|
import { useTimer } from '../../../../common/hooks/useSocket';
|
||||||
@@ -44,7 +44,7 @@ export default function PlaybackTimer(props: PropsWithChildren<PlaybackTimerProp
|
|||||||
|
|
||||||
const isRolling = playback === Playback.Roll;
|
const isRolling = playback === Playback.Roll;
|
||||||
const isWaiting = timer.secondaryTimer !== null && timer.secondaryTimer > 0 && timer.current === null;
|
const isWaiting = timer.secondaryTimer !== null && timer.secondaryTimer > 0 && timer.current === null;
|
||||||
const isOvertime = timer.current !== null && timer.current < 0;
|
const isOvertime = timer.phase === TimerPhase.Negative;
|
||||||
const hasAddedTime = Boolean(timer.addedTime);
|
const hasAddedTime = Boolean(timer.addedTime);
|
||||||
|
|
||||||
const rollLabel = isRolling ? 'Roll mode active' : '';
|
const rollLabel = isRolling ? 'Roll mode active' : '';
|
||||||
|
|||||||
@@ -82,8 +82,6 @@ const withData = <P extends WithDataProps>(Component: ComponentType<P>) => {
|
|||||||
...timer,
|
...timer,
|
||||||
clock,
|
clock,
|
||||||
timerType: eventNow?.timerType ?? null,
|
timerType: eventNow?.timerType ?? null,
|
||||||
timeWarning: eventNow?.timeWarning ?? null,
|
|
||||||
timeDanger: eventNow?.timeWarning ?? null,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// prevent render until we get all the data we need
|
// prevent render until we get all the data we need
|
||||||
|
|||||||
@@ -20,11 +20,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.timer {
|
.timer {
|
||||||
|
opacity: 1;
|
||||||
font-family: var(--font-family-bold-override, $timer-bold-font-family) ;
|
font-family: var(--font-family-bold-override, $timer-bold-font-family) ;
|
||||||
font-size: 20vw;
|
font-size: 20vw;
|
||||||
position: relative;
|
position: relative;
|
||||||
color: var(--timer-color-override, $timer-color);
|
color: var(--timer-color-override, var(--phase-color));
|
||||||
opacity: 1;
|
|
||||||
transition: $viewer-transition-time;
|
transition: $viewer-transition-time;
|
||||||
transition-property: opacity;
|
transition-property: opacity;
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useSearchParams } from 'react-router-dom';
|
import { useSearchParams } from 'react-router-dom';
|
||||||
import { Playback, TimerType, ViewSettings } from 'ontime-types';
|
import { Playback, TimerPhase, TimerType, ViewSettings } from 'ontime-types';
|
||||||
|
|
||||||
import { overrideStylesURL } from '../../../common/api/constants';
|
import { overrideStylesURL } from '../../../common/api/constants';
|
||||||
import { MINIMAL_TIMER_OPTIONS } from '../../../common/components/view-params-editor/constants';
|
import { MINIMAL_TIMER_OPTIONS } from '../../../common/components/view-params-editor/constants';
|
||||||
@@ -126,13 +126,13 @@ export default function MinimalTimer(props: MinimalTimerProps) {
|
|||||||
|
|
||||||
const isPlaying = time.playback !== Playback.Pause;
|
const isPlaying = time.playback !== Playback.Pause;
|
||||||
|
|
||||||
const showEndMessage = (time.current ?? 0) < 0 && viewSettings.endMessage && !hideEndMessage;
|
const finished = time.phase === TimerPhase.Negative;
|
||||||
const finished = time.playback === Playback.Play && (time.current ?? 0) < 0 && time.startedAt;
|
const showEndMessage = finished && viewSettings.endMessage && !hideEndMessage;
|
||||||
const showFinished = finished && !userOptions?.hideOvertime && (time.timerType !== TimerType.Clock || showEndMessage);
|
const showFinished = finished && !userOptions?.hideOvertime && (time.timerType !== TimerType.Clock || showEndMessage);
|
||||||
|
|
||||||
const showProgress = time.playback !== Playback.Stop;
|
const showProgress = time.playback !== Playback.Stop;
|
||||||
const showWarning = (time.current ?? 1) < (time.timeWarning ?? 0);
|
const showWarning = time.phase === TimerPhase.Warning;
|
||||||
const showDanger = (time.current ?? 1) < (time.timeDanger ?? 0);
|
const showDanger = time.phase === TimerPhase.Danger;
|
||||||
|
|
||||||
let timerColor = viewSettings.normalColor;
|
let timerColor = viewSettings.normalColor;
|
||||||
if (!timerIsTimeOfDay && showProgress && showWarning) timerColor = viewSettings.warningColor;
|
if (!timerIsTimeOfDay && showProgress && showWarning) timerColor = viewSettings.warningColor;
|
||||||
@@ -150,7 +150,6 @@ export default function MinimalTimer(props: MinimalTimerProps) {
|
|||||||
|
|
||||||
const timerClasses = `timer ${!isPlaying ? 'timer--paused' : ''} ${showFinished ? 'timer--finished' : ''}`;
|
const timerClasses = `timer ${!isPlaying ? 'timer--paused' : ''} ${showFinished ? 'timer--finished' : ''}`;
|
||||||
const baseClasses = `minimal-timer ${isMirrored ? 'mirror' : ''}`;
|
const baseClasses = `minimal-timer ${isMirrored ? 'mirror' : ''}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={showFinished ? `${baseClasses} minimal-timer--finished` : baseClasses}
|
className={showFinished ? `${baseClasses} minimal-timer--finished` : baseClasses}
|
||||||
@@ -168,12 +167,12 @@ export default function MinimalTimer(props: MinimalTimerProps) {
|
|||||||
<div
|
<div
|
||||||
className={timerClasses}
|
className={timerClasses}
|
||||||
style={{
|
style={{
|
||||||
color: timerColor,
|
|
||||||
fontSize: `${timerFontSize}vw`,
|
fontSize: `${timerFontSize}vw`,
|
||||||
fontFamily: userOptions.font,
|
fontFamily: userOptions.font,
|
||||||
top: userOptions.top,
|
top: userOptions.top,
|
||||||
left: userOptions.left,
|
left: userOptions.left,
|
||||||
backgroundColor: userOptions.textBackground,
|
backgroundColor: userOptions.textBackground,
|
||||||
|
'--phase-color': timerColor,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{display}
|
{display}
|
||||||
|
|||||||
@@ -109,7 +109,7 @@
|
|||||||
.timer {
|
.timer {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
font-family: var(--font-family-override, $viewer-font-family);
|
font-family: var(--font-family-override, $viewer-font-family);
|
||||||
color: var(--timer-color-override, $timer-color);
|
color: var(--timer-color-override, var(--phase-color));
|
||||||
line-height: 0.9em;
|
line-height: 0.9em;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
letter-spacing: 0.05em;
|
letter-spacing: 0.05em;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
Playback,
|
Playback,
|
||||||
Settings,
|
Settings,
|
||||||
TimerMessage,
|
TimerMessage,
|
||||||
|
TimerPhase,
|
||||||
TimerType,
|
TimerType,
|
||||||
ViewSettings,
|
ViewSettings,
|
||||||
} from 'ontime-types';
|
} from 'ontime-types';
|
||||||
@@ -110,14 +111,14 @@ export default function Timer(props: TimerProps) {
|
|||||||
|
|
||||||
const timerIsTimeOfDay = time.timerType === TimerType.Clock;
|
const timerIsTimeOfDay = time.timerType === TimerType.Clock;
|
||||||
|
|
||||||
const finished = time.playback === Playback.Play && (time.current ?? 0) < 0 && time.startedAt;
|
const finished = time.phase === TimerPhase.Negative;
|
||||||
const totalTime = (time.duration ?? 0) + (time.addedTime ?? 0);
|
const totalTime = (time.duration ?? 0) + (time.addedTime ?? 0);
|
||||||
|
|
||||||
const showEndMessage = (time.current ?? 1) < 0 && viewSettings.endMessage;
|
const showEndMessage = finished && viewSettings.endMessage;
|
||||||
const showProgress = time.playback !== Playback.Stop;
|
const showProgress = time.playback !== Playback.Stop;
|
||||||
const showFinished = finished && (time.timerType !== TimerType.Clock || showEndMessage);
|
const showFinished = finished && (time.timerType !== TimerType.Clock || showEndMessage);
|
||||||
const showWarning = (time.current ?? 1) < (eventNow?.timeWarning ?? 0);
|
const showWarning = time.phase === TimerPhase.Warning;
|
||||||
const showDanger = (time.current ?? 1) < (eventNow?.timeDanger ?? 0);
|
const showDanger = time.phase === TimerPhase.Danger;
|
||||||
const showBlinking = pres.blink;
|
const showBlinking = pres.blink;
|
||||||
const showBlackout = pres.blackout;
|
const showBlackout = pres.blackout;
|
||||||
const showClock = time.timerType !== TimerType.Clock;
|
const showClock = time.timerType !== TimerType.Clock;
|
||||||
@@ -173,7 +174,7 @@ export default function Timer(props: TimerProps) {
|
|||||||
className={timerClasses}
|
className={timerClasses}
|
||||||
style={{
|
style={{
|
||||||
fontSize: `${timerFontSize}vw`,
|
fontSize: `${timerFontSize}vw`,
|
||||||
color: timerColor,
|
'--phase-color': timerColor,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{display}
|
{display}
|
||||||
|
|||||||
Reference in New Issue
Block a user