From 3cd6cd2f5530371c6934e480bd35664b05439018 Mon Sep 17 00:00:00 2001 From: Carlos Valente Date: Sat, 21 Jun 2025 20:17:22 +0200 Subject: [PATCH] refactor: rename external message to secondary message --- apps/client/src/common/hooks/useSocket.ts | 8 ++++---- .../control/message/MessageControl.tsx | 20 +++++++++---------- .../features/control/message/TimerPreview.tsx | 4 ++-- .../control/message/TimerViewControl.tsx | 9 +++++---- apps/client/src/views/timer/Timer.tsx | 4 ++-- apps/client/src/views/timer/timer.options.ts | 8 ++++---- apps/client/src/views/timer/timer.utils.ts | 8 ++++---- .../__tests__/automation.validation.test.ts | 4 ++-- .../automation/automation.validation.ts | 2 +- .../automation/clients/ontime.client.ts | 2 +- .../api-integration/integration.controller.ts | 6 +++--- apps/server/src/app.ts | 2 +- ...ervice.test.ts => message.service.test.ts} | 8 ++++---- ...{messageUtils.test.ts => message.utils.ts} | 2 +- .../{MessageService.ts => message.service.ts} | 2 +- .../{messageUtils.ts => message.utils.ts} | 2 +- .../runtime/MessageControl.type.ts | 4 ++-- .../src/definitions/runtime/RuntimeStore.ts | 2 +- 18 files changed, 49 insertions(+), 48 deletions(-) rename apps/server/src/services/message-service/__tests__/{MessageService.test.ts => message.service.test.ts} (87%) rename apps/server/src/services/message-service/__tests__/{messageUtils.test.ts => message.utils.ts} (98%) rename apps/server/src/services/message-service/{MessageService.ts => message.service.ts} (92%) rename apps/server/src/services/message-service/{messageUtils.ts => message.utils.ts} (95%) diff --git a/apps/client/src/common/hooks/useSocket.ts b/apps/client/src/common/hooks/useSocket.ts index ce2a9aad3..a045c1353 100644 --- a/apps/client/src/common/hooks/useSocket.ts +++ b/apps/client/src/common/hooks/useSocket.ts @@ -32,8 +32,8 @@ export const useTimerMessageInput = createSelector((state: RuntimeStore) => ({ })); export const useExternalMessageInput = createSelector((state: RuntimeStore) => ({ - text: state.message.external, - visible: state.message.timer.secondarySource === 'external', + text: state.message.secondary, + visible: state.message.timer.secondarySource === 'secondary', })); export const useMessagePreview = createSelector((state: RuntimeStore) => ({ @@ -41,7 +41,7 @@ export const useMessagePreview = createSelector((state: RuntimeStore) => ({ blackout: state.message.timer.blackout, phase: state.timer.phase, showAuxTimer: state.message.timer.secondarySource === 'aux', - showExternalMessage: state.message.timer.secondarySource === 'external' && Boolean(state.message.external), + showSecondaryMessage: state.message.timer.secondarySource === 'secondary' && Boolean(state.message.secondary), showTimerMessage: state.message.timer.visible && Boolean(state.message.timer.text), timerType: state.eventNow?.timerType ?? null, countToEnd: state.eventNow?.countToEnd ?? false, @@ -50,7 +50,7 @@ export const useMessagePreview = createSelector((state: RuntimeStore) => ({ export const setMessage = { timerText: (payload: string) => sendSocket('message', { timer: { text: payload } }), timerVisible: (payload: boolean) => sendSocket('message', { timer: { visible: payload } }), - externalText: (payload: string) => sendSocket('message', { external: payload }), + secondaryMessage: (payload: string) => sendSocket('message', { secondary: payload }), timerBlink: (payload: boolean) => sendSocket('message', { timer: { blink: payload } }), timerBlackout: (payload: boolean) => sendSocket('message', { timer: { blackout: payload } }), timerSecondary: (payload: TimerMessage['secondarySource']) => diff --git a/apps/client/src/features/control/message/MessageControl.tsx b/apps/client/src/features/control/message/MessageControl.tsx index 41dc4ab56..ebaef268e 100644 --- a/apps/client/src/features/control/message/MessageControl.tsx +++ b/apps/client/src/features/control/message/MessageControl.tsx @@ -1,7 +1,7 @@ import { IoEye, IoEyeOffOutline } from 'react-icons/io5'; import TooltipActionBtn from '../../../common/components/buttons/TooltipActionBtn'; -import { setMessage, useExternalMessageInput, useTimerMessageInput } from '../../../common/hooks/useSocket'; +import { setMessage, useExternalMessageInput as useSecondaryMessageInput, useTimerMessageInput } from '../../../common/hooks/useSocket'; import { tooltipDelayMid } from '../../../ontimeConfig'; import InputRow from './InputRow'; @@ -12,7 +12,7 @@ export default function MessageControl() { <> - + ); } @@ -41,29 +41,29 @@ function TimerMessageInput() { ); } -function ExternalInput() { - const { text, visible } = useExternalMessageInput(); +function SecondaryInput() { + const { text, visible } = useSecondaryMessageInput(); - const toggleExternal = () => { + const toggleSecondary = () => { if (visible) { setMessage.timerSecondary(null); } else { - setMessage.timerSecondary('external'); + setMessage.timerSecondary('secondary'); } }; return ( setMessage.externalText(newValue)} + changeHandler={(newValue) => setMessage.secondaryMessage(newValue)} > : } variant={visible ? 'ontime-filled' : 'ontime-subtle'} diff --git a/apps/client/src/features/control/message/TimerPreview.tsx b/apps/client/src/features/control/message/TimerPreview.tsx index 40c6cbfb8..3a3db72f5 100644 --- a/apps/client/src/features/control/message/TimerPreview.tsx +++ b/apps/client/src/features/control/message/TimerPreview.tsx @@ -12,7 +12,7 @@ import { Corner } from '../../editors/editor-utils/EditorUtils'; import style from './MessageControl.module.scss'; export default function TimerPreview() { - const { blink, blackout, countToEnd, phase, showAuxTimer, showExternalMessage, showTimerMessage, timerType } = + const { blink, blackout, countToEnd, phase, showAuxTimer, showSecondaryMessage, showTimerMessage, timerType } = useMessagePreview(); const { data } = useViewSettings(); @@ -34,7 +34,7 @@ export default function TimerPreview() { // we need to check aux first since it takes priority if (showAuxTimer) return 'Aux Timer'; - if (showExternalMessage) return 'External message'; + if (showSecondaryMessage) return 'Secondary message'; return null; })(); diff --git a/apps/client/src/features/control/message/TimerViewControl.tsx b/apps/client/src/features/control/message/TimerViewControl.tsx index 8bef7ecde..f8197378f 100644 --- a/apps/client/src/features/control/message/TimerViewControl.tsx +++ b/apps/client/src/features/control/message/TimerViewControl.tsx @@ -1,4 +1,5 @@ import { Button } from '@chakra-ui/react'; +import { SecondarySource } from 'ontime-types'; import { setMessage, useTimerViewControl } from '../../../common/hooks/useSocket'; @@ -9,7 +10,7 @@ import style from './MessageControl.module.scss'; export default function TimerControlsPreview() { const { blackout, blink, secondarySource } = useTimerViewControl(); - const toggleSecondary = (newValue: 'aux' | 'external' | null) => { + const toggleSecondary = (newValue: SecondarySource) => { if (secondarySource === newValue) { setMessage.timerSecondary(null); } else { @@ -31,10 +32,10 @@ export default function TimerControlsPreview() {
diff --git a/apps/client/src/views/timer/Timer.tsx b/apps/client/src/views/timer/Timer.tsx index 85de0f405..feda356a2 100644 --- a/apps/client/src/views/timer/Timer.tsx +++ b/apps/client/src/views/timer/Timer.tsx @@ -59,7 +59,7 @@ export default function Timer(props: TimerProps) { hideCards, hideProgress, hideMessage, - hideExternal, + hideSecondary, hideTimerSeconds, removeLeadingZeros, mainSource, @@ -110,7 +110,7 @@ export default function Timer(props: TimerProps) { localisedMinutes, hideTimerSeconds, removeLeadingZeros, - hideExternal, + hideSecondary, ); // gather presentation styles diff --git a/apps/client/src/views/timer/timer.options.ts b/apps/client/src/views/timer/timer.options.ts index e2462d1c0..ae16ac142 100644 --- a/apps/client/src/views/timer/timer.options.ts +++ b/apps/client/src/views/timer/timer.options.ts @@ -99,8 +99,8 @@ export const getTimerOptions = (timeFormat: string, customFields: CustomFields): defaultValue: false, }, { - id: 'hideExternal', - title: 'Hide Auxiliary timer / External message', + id: 'hideSecondary', + title: 'Hide Auxiliary timer / Secondary message', description: 'Prevents the screen from displaying the secondary timer field', type: 'boolean', defaultValue: false, @@ -115,7 +115,7 @@ type TimerOptions = { hideCards: boolean; hideProgress: boolean; hideMessage: boolean; - hideExternal: boolean; + hideSecondary: boolean; hideTimerSeconds: boolean; removeLeadingZeros: boolean; mainSource: keyof OntimeEvent | null; @@ -135,7 +135,7 @@ function getOptionsFromParams(searchParams: URLSearchParams): TimerOptions { hideCards: isStringBoolean(searchParams.get('hideCards')), hideProgress: isStringBoolean(searchParams.get('hideProgress')), hideMessage: isStringBoolean(searchParams.get('hideMessage')), - hideExternal: isStringBoolean(searchParams.get('hideExternal')), + hideSecondary: isStringBoolean(searchParams.get('hideSecondary')), hideTimerSeconds: isStringBoolean(searchParams.get('hideTimerSeconds')), removeLeadingZeros: !isStringBoolean(searchParams.get('showLeadingZeros')), diff --git a/apps/client/src/views/timer/timer.utils.ts b/apps/client/src/views/timer/timer.utils.ts index ae85030ff..4dc67a883 100644 --- a/apps/client/src/views/timer/timer.utils.ts +++ b/apps/client/src/views/timer/timer.utils.ts @@ -111,9 +111,9 @@ export function getSecondaryDisplay( localisedMinutes: string, removeSeconds: boolean, removeLeadingZero: boolean, - hideExternal: boolean, + hideSecondary: boolean, ): string | undefined { - if (hideExternal) { + if (hideSecondary) { return; } if (message.timer.secondarySource === 'aux') { @@ -122,8 +122,8 @@ export function getSecondaryDisplay( removeLeadingZero, }); } - if (message.timer.secondarySource === 'external' && message.external) { - return message.external; + if (message.timer.secondarySource === 'secondary' && message.secondary) { + return message.secondary; } return; } diff --git a/apps/server/src/api-data/automation/__tests__/automation.validation.test.ts b/apps/server/src/api-data/automation/__tests__/automation.validation.test.ts index c22060009..1ae0d08a7 100644 --- a/apps/server/src/api-data/automation/__tests__/automation.validation.test.ts +++ b/apps/server/src/api-data/automation/__tests__/automation.validation.test.ts @@ -158,10 +158,10 @@ describe('parseOutput', () => { parseOutput({ type: 'ontime', action: 'message-secondary', - secondarySource: 'external', + secondarySource: 'secondary', }), ).toMatchObject({ - secondarySource: 'external', + secondarySource: 'secondary', }); }); }); diff --git a/apps/server/src/api-data/automation/automation.validation.ts b/apps/server/src/api-data/automation/automation.validation.ts index 6cecfb0b3..340a8abc7 100644 --- a/apps/server/src/api-data/automation/automation.validation.ts +++ b/apps/server/src/api-data/automation/automation.validation.ts @@ -254,6 +254,6 @@ function indeterminateBooleanString(value: string): boolean | undefined { */ function chooseSecondarySource(value: string): SecondarySource { if (value === 'aux') return 'aux'; - if (value === 'external') return 'external'; + if (value === 'secondary') return 'secondary'; return null; } diff --git a/apps/server/src/api-data/automation/clients/ontime.client.ts b/apps/server/src/api-data/automation/clients/ontime.client.ts index 1c140bcae..70b659b70 100644 --- a/apps/server/src/api-data/automation/clients/ontime.client.ts +++ b/apps/server/src/api-data/automation/clients/ontime.client.ts @@ -2,7 +2,7 @@ import { LogOrigin, OntimeAction } from 'ontime-types'; import { logger } from '../../../classes/Logger.js'; import { auxTimerService } from '../../../services/aux-timer-service/AuxTimerService.js'; -import * as messageService from '../../../services/message-service/MessageService.js'; +import * as messageService from '../../../services/message-service/message.service.js'; export function toOntimeAction(action: OntimeAction) { const actionType = action.action; diff --git a/apps/server/src/api-integration/integration.controller.ts b/apps/server/src/api-integration/integration.controller.ts index 4d78d6757..10a94ab20 100644 --- a/apps/server/src/api-integration/integration.controller.ts +++ b/apps/server/src/api-integration/integration.controller.ts @@ -13,8 +13,8 @@ import { DeepPartial } from 'ts-essentials'; import { ONTIME_VERSION } from '../ONTIME_VERSION.js'; import { auxTimerService } from '../services/aux-timer-service/AuxTimerService.js'; -import * as messageService from '../services/message-service/MessageService.js'; -import { validateMessage, validateTimerMessage } from '../services/message-service/messageUtils.js'; +import * as messageService from '../services/message-service/message.service.js'; +import { validateMessage, validateTimerMessage } from '../services/message-service/message.utils.js'; import { runtimeService } from '../services/runtime-service/RuntimeService.js'; import { eventStore } from '../stores/EventStore.js'; import * as assert from '../utils/assert.js'; @@ -101,7 +101,7 @@ const actionHandlers: Record = { const patch: DeepPartial = { timer: 'timer' in payload ? validateTimerMessage(payload.timer) : undefined, - external: 'external' in payload ? validateMessage(payload.external) : undefined, + secondary: 'secondary' in payload ? validateMessage(payload.secondary) : undefined, }; const newMessage = messageService.patch(patch); diff --git a/apps/server/src/app.ts b/apps/server/src/app.ts index 9d77e3258..97e5aec1a 100644 --- a/apps/server/src/app.ts +++ b/apps/server/src/app.ts @@ -33,7 +33,7 @@ import { populateStyles } from './setup/loadStyles.js'; import { eventStore } from './stores/EventStore.js'; import { runtimeService } from './services/runtime-service/RuntimeService.js'; import { restoreService } from './services/RestoreService.js'; -import * as messageService from './services/message-service/MessageService.js'; +import * as messageService from './services/message-service/message.service.js'; import { populateDemo } from './setup/loadDemo.js'; import { getState } from './stores/runtimeState.js'; import { initRundown } from './api-data/rundown/rundown.service.js'; diff --git a/apps/server/src/services/message-service/__tests__/MessageService.test.ts b/apps/server/src/services/message-service/__tests__/message.service.test.ts similarity index 87% rename from apps/server/src/services/message-service/__tests__/MessageService.test.ts rename to apps/server/src/services/message-service/__tests__/message.service.test.ts index e37fa6910..6eec95a46 100644 --- a/apps/server/src/services/message-service/__tests__/MessageService.test.ts +++ b/apps/server/src/services/message-service/__tests__/message.service.test.ts @@ -1,6 +1,6 @@ import { RuntimeStore } from 'ontime-types'; -import * as messageService from '../MessageService.js'; +import * as messageService from '../message.service.js'; describe('MessageService', () => { let store: Partial; @@ -17,12 +17,12 @@ describe('MessageService', () => { it('should patch the message state', () => { const newState = messageService.patch({ timer: { text: 'new text', visible: true }, - external: 'external', + secondary: 'secondary', }); expect(newState).toMatchObject({ timer: { text: 'new text', visible: true, blackout: false, blink: false, secondarySource: null }, - external: 'external', + secondary: 'secondary', }); }); @@ -33,7 +33,7 @@ describe('MessageService', () => { expect(newState).toMatchObject({ timer: { text: 'initial text', visible: true, blackout: false, blink: false, secondarySource: null }, - external: '', + secondary: '', }); }); }); diff --git a/apps/server/src/services/message-service/__tests__/messageUtils.test.ts b/apps/server/src/services/message-service/__tests__/message.utils.ts similarity index 98% rename from apps/server/src/services/message-service/__tests__/messageUtils.test.ts rename to apps/server/src/services/message-service/__tests__/message.utils.ts index 50db0eadc..a4354bde1 100644 --- a/apps/server/src/services/message-service/__tests__/messageUtils.test.ts +++ b/apps/server/src/services/message-service/__tests__/message.utils.ts @@ -1,4 +1,4 @@ -import { validateMessage, validateTimerMessage } from '../messageUtils.js'; +import { validateMessage, validateTimerMessage } from '../message.utils.js'; describe('validateMessage()', () => { it('returns a valid Message object', () => { diff --git a/apps/server/src/services/message-service/MessageService.ts b/apps/server/src/services/message-service/message.service.ts similarity index 92% rename from apps/server/src/services/message-service/MessageService.ts rename to apps/server/src/services/message-service/message.service.ts index c943cb92b..f739ca525 100644 --- a/apps/server/src/services/message-service/MessageService.ts +++ b/apps/server/src/services/message-service/message.service.ts @@ -43,7 +43,7 @@ export function patch(patch: DeepPartial): MessageState { const newState = { ...getState() }; if ('timer' in patch) newState.timer = { ...newState.timer, ...patch.timer }; - if ('external' in patch && patch.external !== undefined) newState.external = patch.external; + if ('secondary' in patch && patch.secondary !== undefined) newState.secondary = patch.secondary; throttledSet('message', newState); return newState; diff --git a/apps/server/src/services/message-service/messageUtils.ts b/apps/server/src/services/message-service/message.utils.ts similarity index 95% rename from apps/server/src/services/message-service/messageUtils.ts rename to apps/server/src/services/message-service/message.utils.ts index e10195c60..985cea039 100644 --- a/apps/server/src/services/message-service/messageUtils.ts +++ b/apps/server/src/services/message-service/message.utils.ts @@ -33,7 +33,7 @@ export function validateTimerMessage(message: unknown): Partial { * Asserts that the secondary value is one of the permitted values */ function assertSecondary(source: unknown): source is TimerMessage['secondarySource'] { - return source === 'aux' || source === 'external' || source === null; + return source === 'aux' || source === 'secondary' || source === null; } /** diff --git a/packages/types/src/definitions/runtime/MessageControl.type.ts b/packages/types/src/definitions/runtime/MessageControl.type.ts index 850574ddc..a1a994245 100644 --- a/packages/types/src/definitions/runtime/MessageControl.type.ts +++ b/packages/types/src/definitions/runtime/MessageControl.type.ts @@ -1,4 +1,4 @@ -export type SecondarySource = 'aux' | 'external' | null; +export type SecondarySource = 'aux' | 'secondary' | null; export type TimerMessage = { text: string; @@ -10,5 +10,5 @@ export type TimerMessage = { export type MessageState = { timer: TimerMessage; - external: string; + secondary: string; }; diff --git a/packages/types/src/definitions/runtime/RuntimeStore.ts b/packages/types/src/definitions/runtime/RuntimeStore.ts index 39dd4d8ed..4cb4e193b 100644 --- a/packages/types/src/definitions/runtime/RuntimeStore.ts +++ b/packages/types/src/definitions/runtime/RuntimeStore.ts @@ -27,7 +27,7 @@ export const runtimeStorePlaceholder: Readonly = { blackout: false, secondarySource: null, }, - external: '', + secondary: '', }, runtime: { selectedEventIndex: null, // changes if rundown changes or we load a new event