refactor: timer design review

This commit is contained in:
Carlos Valente
2025-07-12 11:55:49 +02:00
parent 2aac4cb06d
commit 05d01e0863
9 changed files with 131 additions and 33 deletions
@@ -26,10 +26,10 @@ describe('makeOptionsFromCustomFields()', () => {
]; ];
const result = makeOptionsFromCustomFields(testCustomFields, additionalData); const result = makeOptionsFromCustomFields(testCustomFields, additionalData);
expect(result).toStrictEqual([ expect(result).toStrictEqual([
{ value: 'custom-field1', label: 'Custom: Field 1' },
{ value: 'custom-field2', label: 'Custom: Field 2' },
{ value: 'test1', label: 'Test 1' }, { value: 'test1', label: 'Test 1' },
{ value: 'test2', label: 'Test 2' }, { value: 'test2', label: 'Test 2' },
{ value: 'custom-field1', label: 'Custom: Field 1' },
{ value: 'custom-field2', label: 'Custom: Field 2' },
]); ]);
}); });
@@ -4,8 +4,8 @@ export const getTimeOption = (timeFormat: string): ParamField => {
const placeholder = `${timeFormat} (default)`; const placeholder = `${timeFormat} (default)`;
return { return {
id: 'timeformat', id: 'timeformat',
title: 'Time format string, taken from the Application Settings', title: 'Clock time format, defaults to value from the Settings',
description: 'Format for auxiliar time fields (not the running), eg. HH:mm:ss or hh:mm:ss a, see docs for help', description: 'Format for the Time Now field, eg. HH:mm:ss or hh:mm:ss a, see docs for help',
type: 'string', type: 'string',
placeholder, placeholder,
}; };
@@ -13,7 +13,7 @@ export function makeOptionsFromCustomFields(
additionalOptions: SelectOption[] = [], additionalOptions: SelectOption[] = [],
filterImageType = true, filterImageType = true,
): SelectOption[] { ): SelectOption[] {
const options: SelectOption[] = []; const options: SelectOption[] = [...additionalOptions];
// Add custom fields first // Add custom fields first
for (const [key, value] of Object.entries(customFields)) { for (const [key, value] of Object.entries(customFields)) {
@@ -27,7 +27,7 @@ export function makeOptionsFromCustomFields(
}); });
} }
return options.concat(additionalOptions); return options;
} }
/** /**
@@ -9,7 +9,6 @@ import Input from '../../../common/components/input/input/Input';
import TimeInput from '../../../common/components/input/time-input/TimeInput'; import TimeInput from '../../../common/components/input/time-input/TimeInput';
import Modal from '../../../common/components/modal/Modal'; import Modal from '../../../common/components/modal/Modal';
import Select from '../../../common/components/select/Select'; import Select from '../../../common/components/select/Select';
import Switch from '../../../common/components/switch/Switch';
import { editorSettingsDefaults, useEditorSettings } from '../../../common/stores/editorSettings'; import { editorSettingsDefaults, useEditorSettings } from '../../../common/stores/editorSettings';
import * as Panel from '../panel-utils/PanelUtils'; import * as Panel from '../panel-utils/PanelUtils';
@@ -55,6 +55,18 @@ export function isStringBoolean(text: string | null) {
return text?.toLowerCase() === 'true' || text === '1'; return text?.toLowerCase() === 'true' || text === '1';
} }
/**
* Prepares a colour string for use in views
* Colours in params do not have the #prefix
*/
export function makeColourString(hex: string | null): string | undefined {
if (!hex) {
return undefined;
}
// ensure the hex starts with a #
return hex.startsWith('#') ? hex : `#${hex}`;
}
/** /**
* Retrieves a dynamic property from an event * Retrieves a dynamic property from an event
* Considers custom fields * Considers custom fields
+3 -3
View File
@@ -9,7 +9,7 @@
transition: opacity 0.5s ease-in-out; transition: opacity 0.5s ease-in-out;
font-family: var(--font-family-override, $viewer-font-family); font-family: var(--font-family-override, $viewer-font-family);
background: var(--background-color-override, $viewer-background-color); background: var(--timer-bg, var(--background-color-override, $viewer-background-color));
color: var(--color-override, $viewer-color); color: var(--color-override, $viewer-color);
gap: $view-element-gap; gap: $view-element-gap;
padding: $view-outer-padding; padding: $view-outer-padding;
@@ -100,8 +100,8 @@
.timer { .timer {
opacity: 1; opacity: 1;
font-family: var(--font-family-override, $viewer-font-family); font-family: var(--timer-font, var(--font-family-override, $viewer-font-family));
color: var(--timer-color-override, var(--phase-color)); color: var(--timer-colour, 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;
+31 -8
View File
@@ -42,21 +42,36 @@ interface TimerProps {
viewSettings: ViewSettings; viewSettings: ViewSettings;
} }
export default function Timer(props: TimerProps) { export default function Timer({
const { customFields, eventNow, eventNext, general, isMirrored, message, settings, time, viewSettings } = props; customFields,
eventNow,
eventNext,
general,
isMirrored,
message,
settings,
time,
viewSettings,
}: TimerProps) {
const auxTimer = useAuxTimersTime(); const auxTimer = useAuxTimersTime();
const { const {
hideClock, hideClock,
hideCards, hideCards,
hideProgress, hideProgress,
hideMessage, hideMessage,
hideSecondary, hideSecondary,
hideLogo,
hideTimerSeconds, hideTimerSeconds,
removeLeadingZeros, removeLeadingZeros,
mainSource, mainSource,
secondarySource, secondarySource,
timerType, timerType,
freezeOvertime,
freezeMessage,
hideOvertime,
font,
keyColour,
textColour,
} = useTimerOptions(); } = useTimerOptions();
const { getLocalizedString } = useTranslation(); const { getLocalizedString } = useTranslation();
@@ -71,7 +86,9 @@ export default function Timer(props: TimerProps) {
time.timerType, time.timerType,
time.countToEnd, time.countToEnd,
time.phase, time.phase,
viewSettings, freezeOvertime,
freezeMessage,
hideOvertime,
); );
const isPlaying = getIsPlaying(time.playback); const isPlaying = getIsPlaying(time.playback);
const showClock = !hideClock && getShowClock(viewTimerType); const showClock = !hideClock && getShowClock(viewTimerType);
@@ -90,7 +107,7 @@ export default function Timer(props: TimerProps) {
// gather timer data // gather timer data
const totalTime = getTotalTime(time.duration, time.addedTime); const totalTime = getTotalTime(time.duration, time.addedTime);
const clock = formatTime(time.clock); const clock = formatTime(time.clock);
const stageTimer = getTimerByType(viewSettings.freezeEnd, time, timerType); const stageTimer = getTimerByType(freezeOvertime, time, timerType);
const display = getFormattedTimer(stageTimer, viewTimerType, localisedMinutes, { const display = getFormattedTimer(stageTimer, viewTimerType, localisedMinutes, {
removeSeconds: hideTimerSeconds, removeSeconds: hideTimerSeconds,
removeLeadingZero: removeLeadingZeros, removeLeadingZero: removeLeadingZeros,
@@ -121,6 +138,11 @@ export default function Timer(props: TimerProps) {
// gather presentation styles // gather presentation styles
const timerColour = getTimerColour(viewSettings, showWarning, showDanger); const timerColour = getTimerColour(viewSettings, showWarning, showDanger);
const { timerFontSize, externalFontSize } = getEstimatedFontSize(display, secondaryContent); const { timerFontSize, externalFontSize } = getEstimatedFontSize(display, secondaryContent);
const userStyles = {
...(keyColour && { '--timer-bg': keyColour }),
...(textColour && { '--timer-colour': textColour }),
...(font && { '--timer-font': font }),
};
// gather option data // gather option data
const defaultFormat = getDefaultFormat(settings?.timeFormat); const defaultFormat = getDefaultFormat(settings?.timeFormat);
@@ -128,10 +150,11 @@ export default function Timer(props: TimerProps) {
return ( return (
<div <div
className={cx(['stage-timer', isMirrored && 'mirror', showFinished && 'stage-timer--finished'])}
data-testid='timer-view' data-testid='timer-view'
className={cx(['stage-timer', isMirrored && 'mirror', showFinished && 'stage-timer--finished'])}
style={userStyles}
> >
{general?.logo && <ViewLogo name={general.logo} className='logo' />} {!hideLogo && general?.logo && <ViewLogo name={general.logo} className='logo' />}
<ViewParamsEditor viewOptions={timerOptions} /> <ViewParamsEditor viewOptions={timerOptions} />
@@ -155,7 +178,7 @@ export default function Timer(props: TimerProps) {
<div className={cx(['timer-container', message.timer.blink && !showOverlay && 'blink'])}> <div className={cx(['timer-container', message.timer.blink && !showOverlay && 'blink'])}>
{showEndMessage ? ( {showEndMessage ? (
<FitText mode='multi' min={64} max={256} className='end-message'> <FitText mode='multi' min={64} max={256} className='end-message'>
{viewSettings.endMessage} {freezeMessage}
</FitText> </FitText>
) : ( ) : (
<div <div
+73 -2
View File
@@ -12,7 +12,7 @@ import {
import { OptionTitle } from '../../common/components/view-params-editor/constants'; import { OptionTitle } from '../../common/components/view-params-editor/constants';
import { ViewOption } from '../../common/components/view-params-editor/viewParams.types'; import { ViewOption } from '../../common/components/view-params-editor/viewParams.types';
import { makeOptionsFromCustomFields } from '../../common/components/view-params-editor/viewParams.utils'; import { makeOptionsFromCustomFields } from '../../common/components/view-params-editor/viewParams.utils';
import { isStringBoolean } from '../../features/viewers/common/viewUtils'; import { isStringBoolean, makeColourString } from '../../features/viewers/common/viewUtils';
// manually match the properties of TimerType excluding the None // manually match the properties of TimerType excluding the None
const timerDisplayOptions: SelectOption[] = [ const timerDisplayOptions: SelectOption[] = [
@@ -48,6 +48,29 @@ export const getTimerOptions = (timeFormat: string, customFields: CustomFields):
values: timerDisplayOptions, values: timerDisplayOptions,
defaultValue: 'no-overrides', defaultValue: 'no-overrides',
}, },
{
id: 'freezeOvertime',
title: 'Freeze Overtime',
description: 'If active, the timer will not count into negative numbers',
type: 'boolean',
defaultValue: false,
},
{
id: 'freezeMessage',
title: 'Freeze Message',
description:
'An optional message to show when the timer is in overtime (must be set in combination with Freeze Overtime)',
type: 'string',
defaultValue: '',
placeholder: 'e.g. Time is up!',
},
{
id: 'hideOvertime',
title: 'Hide Overtime',
description: 'Whether to suppress overtime styles (red borders and red text)',
type: 'boolean',
defaultValue: false,
},
], ],
}, },
{ {
@@ -72,7 +95,6 @@ export const getTimerOptions = (timeFormat: string, customFields: CustomFields):
}, },
], ],
}, },
{ {
title: OptionTitle.ElementVisibility, title: OptionTitle.ElementVisibility,
collapsible: true, collapsible: true,
@@ -112,6 +134,40 @@ export const getTimerOptions = (timeFormat: string, customFields: CustomFields):
type: 'boolean', type: 'boolean',
defaultValue: false, defaultValue: false,
}, },
{
id: 'hideLogo',
title: 'Hide the project logo',
description: 'Prevents the screen from displaying the given project logo',
type: 'boolean',
defaultValue: false,
},
],
},
{
title: OptionTitle.StyleOverride,
collapsible: true,
options: [
{
id: 'font',
title: 'Font',
description: 'Font family, will use the fonts available in the system',
type: 'string',
placeholder: 'Open Sans (default)',
},
{
id: 'keyColour',
title: 'Key Colour',
description: 'Background or key colour for entire view. Default: #101010',
type: 'colour',
defaultValue: '101010',
},
{
id: 'textColour',
title: 'Text Colour',
description: 'Text colour. Default: #f6f6f6',
type: 'colour',
defaultValue: 'f6f6f6',
},
], ],
}, },
]; ];
@@ -123,11 +179,18 @@ type TimerOptions = {
hideProgress: boolean; hideProgress: boolean;
hideMessage: boolean; hideMessage: boolean;
hideSecondary: boolean; hideSecondary: boolean;
hideLogo: boolean;
hideTimerSeconds: boolean; hideTimerSeconds: boolean;
removeLeadingZeros: boolean; removeLeadingZeros: boolean;
mainSource: keyof OntimeEvent | null; mainSource: keyof OntimeEvent | null;
secondarySource: keyof OntimeEvent | null; secondarySource: keyof OntimeEvent | null;
timerType?: TimerType; timerType?: TimerType;
freezeOvertime: boolean;
freezeMessage: string;
hideOvertime: boolean;
font?: string;
keyColour?: string;
textColour?: string;
}; };
/** /**
@@ -143,6 +206,7 @@ function getOptionsFromParams(searchParams: URLSearchParams): TimerOptions {
hideProgress: isStringBoolean(searchParams.get('hideProgress')), hideProgress: isStringBoolean(searchParams.get('hideProgress')),
hideMessage: isStringBoolean(searchParams.get('hideMessage')), hideMessage: isStringBoolean(searchParams.get('hideMessage')),
hideSecondary: isStringBoolean(searchParams.get('hideSecondary')), hideSecondary: isStringBoolean(searchParams.get('hideSecondary')),
hideLogo: isStringBoolean(searchParams.get('hideLogo')),
hideTimerSeconds: isStringBoolean(searchParams.get('hideTimerSeconds')), hideTimerSeconds: isStringBoolean(searchParams.get('hideTimerSeconds')),
removeLeadingZeros: !isStringBoolean(searchParams.get('showLeadingZeros')), removeLeadingZeros: !isStringBoolean(searchParams.get('showLeadingZeros')),
@@ -151,6 +215,13 @@ function getOptionsFromParams(searchParams: URLSearchParams): TimerOptions {
// none doesnt make sense as a configuration of the view // none doesnt make sense as a configuration of the view
timerType: timerType === TimerType.None ? undefined : timerType, timerType: timerType === TimerType.None ? undefined : timerType,
freezeOvertime: isStringBoolean(searchParams.get('freezeOvertime')),
freezeMessage: searchParams.get('freezeMessage') ?? '',
hideOvertime: isStringBoolean(searchParams.get('hideOvertime')),
font: searchParams.get('font') ?? undefined,
keyColour: makeColourString(searchParams.get('keyColour')),
textColour: makeColourString(searchParams.get('textColour')),
}; };
} }
+6 -13
View File
@@ -1,13 +1,4 @@
import { import { MaybeNumber, MessageState, OntimeEvent, Playback, TimerMessage, TimerPhase, TimerType } from 'ontime-types';
MaybeNumber,
MessageState,
OntimeEvent,
Playback,
TimerMessage,
TimerPhase,
TimerType,
ViewSettings,
} from 'ontime-types';
import { isPlaybackActive } from 'ontime-utils'; import { isPlaybackActive } from 'ontime-utils';
import { getFormattedTimer, getPropertyValue } from '../../features/viewers/common/viewUtils'; import { getFormattedTimer, getPropertyValue } from '../../features/viewers/common/viewUtils';
@@ -90,13 +81,15 @@ export function getShowModifiers(
timerType: TimerType, timerType: TimerType,
countToEnd: boolean, countToEnd: boolean,
phase: TimerPhase, phase: TimerPhase,
viewSettings: ViewSettings, freezeOvertime: boolean,
freezeMessage: string,
hideOvertime: boolean,
) { ) {
const showModifiers = timerType === TimerType.CountDown || countToEnd; const showModifiers = timerType === TimerType.CountDown || countToEnd;
const finished = phase === TimerPhase.Overtime; const finished = phase === TimerPhase.Overtime;
return { return {
showEndMessage: showModifiers && finished && viewSettings.endMessage, showEndMessage: showModifiers && finished && freezeOvertime && freezeMessage !== '',
showFinished: showModifiers && finished, // ???? showFinished: showModifiers && !hideOvertime && finished,
showWarning: showModifiers && phase === TimerPhase.Warning, showWarning: showModifiers && phase === TimerPhase.Warning,
showDanger: showModifiers && phase === TimerPhase.Danger, showDanger: showModifiers && phase === TimerPhase.Danger,
}; };