mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-21 23:19:09 +00:00
refactor: consolidate language of AuxTimer (#896)
This commit is contained in:
@@ -86,13 +86,13 @@ export const useInfoPanel = () => {
|
|||||||
return useRuntimeStore(featureSelector);
|
return useRuntimeStore(featureSelector);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useExtraTimerTime = () => {
|
export const useAuxTimerTime = () => {
|
||||||
const featureSelector = (state: RuntimeStore) => state.auxtimer1.current;
|
const featureSelector = (state: RuntimeStore) => state.auxtimer1.current;
|
||||||
|
|
||||||
return useRuntimeStore(featureSelector);
|
return useRuntimeStore(featureSelector);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useExtraTimerControl = () => {
|
export const useAuxTimerControl = () => {
|
||||||
const featureSelector = (state: RuntimeStore) => ({
|
const featureSelector = (state: RuntimeStore) => ({
|
||||||
playback: state.auxtimer1.playback,
|
playback: state.auxtimer1.playback,
|
||||||
direction: state.auxtimer1.direction,
|
direction: state.auxtimer1.direction,
|
||||||
@@ -101,7 +101,7 @@ export const useExtraTimerControl = () => {
|
|||||||
return useRuntimeStore(featureSelector);
|
return useRuntimeStore(featureSelector);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const setExtraTimer = {
|
export const setAuxTimer = {
|
||||||
start: () => socketSendJson('auxtimer', { '1': SimplePlayback.Start }),
|
start: () => socketSendJson('auxtimer', { '1': SimplePlayback.Start }),
|
||||||
pause: () => socketSendJson('auxtimer', { '1': SimplePlayback.Pause }),
|
pause: () => socketSendJson('auxtimer', { '1': SimplePlayback.Pause }),
|
||||||
stop: () => socketSendJson('auxtimer', { '1': SimplePlayback.Stop }),
|
stop: () => socketSendJson('auxtimer', { '1': SimplePlayback.Stop }),
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { Playback } from 'ontime-types';
|
|||||||
import { usePlaybackControl } from '../../../common/hooks/useSocket';
|
import { usePlaybackControl } from '../../../common/hooks/useSocket';
|
||||||
|
|
||||||
import AddTime from './add-time/AddTime';
|
import AddTime from './add-time/AddTime';
|
||||||
import { ExtraTimer } from './extra-timer/ExtraTimer';
|
import { AuxTimer } from './aux-timer/AuxTimer';
|
||||||
import PlaybackButtons from './playback-buttons/PlaybackButtons';
|
import PlaybackButtons from './playback-buttons/PlaybackButtons';
|
||||||
import PlaybackTimer from './playback-timer/PlaybackTimer';
|
import PlaybackTimer from './playback-timer/PlaybackTimer';
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ export default function PlaybackControl() {
|
|||||||
numEvents={data.numEvents}
|
numEvents={data.numEvents}
|
||||||
selectedEventIndex={data.selectedEventIndex}
|
selectedEventIndex={data.selectedEventIndex}
|
||||||
/>
|
/>
|
||||||
<ExtraTimer />
|
<AuxTimer />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-9
@@ -6,16 +6,16 @@ import { IoStop } from '@react-icons/all-files/io5/IoStop';
|
|||||||
import { Playback, SimpleDirection, SimplePlayback } from 'ontime-types';
|
import { Playback, SimpleDirection, SimplePlayback } from 'ontime-types';
|
||||||
|
|
||||||
import TimeInput from '../../../../common/components/input/time-input/TimeInput';
|
import TimeInput from '../../../../common/components/input/time-input/TimeInput';
|
||||||
import { setExtraTimer, useExtraTimerControl, useExtraTimerTime } from '../../../../common/hooks/useSocket';
|
import { setAuxTimer, useAuxTimerControl, useAuxTimerTime } from '../../../../common/hooks/useSocket';
|
||||||
import { forgivingStringToMillis } from '../../../../common/utils/dateConfig';
|
import { forgivingStringToMillis } from '../../../../common/utils/dateConfig';
|
||||||
import TapButton from '../tap-button/TapButton';
|
import TapButton from '../tap-button/TapButton';
|
||||||
|
|
||||||
import style from './ExtraTimer.module.scss';
|
import style from './AuxTimer.module.scss';
|
||||||
|
|
||||||
export function ExtraTimer() {
|
export function AuxTimer() {
|
||||||
const { playback, direction } = useExtraTimerControl();
|
const { playback, direction } = useAuxTimerControl();
|
||||||
|
|
||||||
const { start, pause, stop, setDirection } = setExtraTimer;
|
const { start, pause, stop, setDirection } = setAuxTimer;
|
||||||
|
|
||||||
const toggleDirection = () => {
|
const toggleDirection = () => {
|
||||||
const newDirection = direction === SimpleDirection.CountDown ? SimpleDirection.CountUp : SimpleDirection.CountDown;
|
const newDirection = direction === SimpleDirection.CountDown ? SimpleDirection.CountUp : SimpleDirection.CountDown;
|
||||||
@@ -30,7 +30,7 @@ export function ExtraTimer() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={style.extraRow}>
|
<div className={style.extraRow}>
|
||||||
<ExtraTimeInput />
|
<AuxTimerInput />
|
||||||
<TapButton onClick={toggleDirection} aspect='tight'>
|
<TapButton onClick={toggleDirection} aspect='tight'>
|
||||||
{direction === SimpleDirection.CountDown && <IoArrowDown data-testid='aux-timer-direction' />}
|
{direction === SimpleDirection.CountDown && <IoArrowDown data-testid='aux-timer-direction' />}
|
||||||
{direction === SimpleDirection.CountUp && <IoArrowUp data-testid='aux-timer-direction' />}
|
{direction === SimpleDirection.CountUp && <IoArrowUp data-testid='aux-timer-direction' />}
|
||||||
@@ -59,9 +59,9 @@ export function ExtraTimer() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ExtraTimeInput() {
|
function AuxTimerInput() {
|
||||||
const time = useExtraTimerTime();
|
const time = useAuxTimerTime();
|
||||||
const { setDuration } = setExtraTimer;
|
const { setDuration } = setAuxTimer;
|
||||||
|
|
||||||
const handleTimeUpdate = (_field: string, value: string) => {
|
const handleTimeUpdate = (_field: string, value: string) => {
|
||||||
const newTime = forgivingStringToMillis(value);
|
const newTime = forgivingStringToMillis(value);
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { DeepPartial, MessageState, OntimeEvent, SimpleDirection, SimplePlayback } from 'ontime-types';
|
import { DeepPartial, MessageState, OntimeEvent, SimpleDirection, SimplePlayback } from 'ontime-types';
|
||||||
|
|
||||||
import { ONTIME_VERSION } from '../ONTIME_VERSION.js';
|
import { ONTIME_VERSION } from '../ONTIME_VERSION.js';
|
||||||
import { extraTimerService } from '../services/extra-timer-service/ExtraTimerService.js';
|
import { auxTimerService } from '../services/aux-timer-service/AuxTimerService.js';
|
||||||
import { messageService } from '../services/message-service/MessageService.js';
|
import { messageService } from '../services/message-service/MessageService.js';
|
||||||
import { validateMessage, validateTimerMessage } from '../services/message-service/messageUtils.js';
|
import { validateMessage, validateTimerMessage } from '../services/message-service/messageUtils.js';
|
||||||
import { runtimeService } from '../services/runtime-service/RuntimeService.js';
|
import { runtimeService } from '../services/runtime-service/RuntimeService.js';
|
||||||
@@ -190,26 +190,26 @@ const actionHandlers: Record<string, ActionHandler> = {
|
|||||||
const command = payload['1'];
|
const command = payload['1'];
|
||||||
if (typeof command === 'string') {
|
if (typeof command === 'string') {
|
||||||
if (command === SimplePlayback.Start) {
|
if (command === SimplePlayback.Start) {
|
||||||
const reply = extraTimerService.start();
|
const reply = auxTimerService.start();
|
||||||
return { payload: reply };
|
return { payload: reply };
|
||||||
}
|
}
|
||||||
if (command === SimplePlayback.Pause) {
|
if (command === SimplePlayback.Pause) {
|
||||||
const reply = extraTimerService.pause();
|
const reply = auxTimerService.pause();
|
||||||
return { payload: reply };
|
return { payload: reply };
|
||||||
}
|
}
|
||||||
if (command === SimplePlayback.Stop) {
|
if (command === SimplePlayback.Stop) {
|
||||||
const reply = extraTimerService.stop();
|
const reply = auxTimerService.stop();
|
||||||
return { payload: reply };
|
return { payload: reply };
|
||||||
}
|
}
|
||||||
} else if (command && typeof command === 'object') {
|
} else if (command && typeof command === 'object') {
|
||||||
const reply = { payload: {} };
|
const reply = { payload: {} };
|
||||||
if ('duration' in command) {
|
if ('duration' in command) {
|
||||||
const time = numberOrError(command.duration);
|
const time = numberOrError(command.duration);
|
||||||
reply.payload = extraTimerService.setTime(time * 1000); //frontend is seconds based
|
reply.payload = auxTimerService.setTime(time * 1000); //frontend is seconds based
|
||||||
}
|
}
|
||||||
if ('direction' in command) {
|
if ('direction' in command) {
|
||||||
if (command.direction === SimpleDirection.CountUp || command.direction === SimpleDirection.CountDown) {
|
if (command.direction === SimpleDirection.CountUp || command.direction === SimpleDirection.CountDown) {
|
||||||
reply.payload = extraTimerService.setDirection(command.direction);
|
reply.payload = auxTimerService.setDirection(command.direction);
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid direction payload');
|
throw new Error('Invalid direction payload');
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -6,7 +6,7 @@ import { eventStore } from '../../stores/EventStore.js';
|
|||||||
export type EmitFn = (state: SimpleTimerState) => void;
|
export type EmitFn = (state: SimpleTimerState) => void;
|
||||||
export type GetTimeFn = () => number;
|
export type GetTimeFn = () => number;
|
||||||
|
|
||||||
export class ExtraTimerService {
|
export class AuxTimerService {
|
||||||
private timer: SimpleTimer;
|
private timer: SimpleTimer;
|
||||||
private interval: NodeJS.Timer | null = null;
|
private interval: NodeJS.Timer | null = null;
|
||||||
private emit: EmitFn;
|
private emit: EmitFn;
|
||||||
@@ -76,4 +76,4 @@ function broadcastReturn(_target: any, _propertyKey: string, descriptor: Propert
|
|||||||
const emit = (state: SimpleTimerState) => eventStore.set('auxtimer1', state);
|
const emit = (state: SimpleTimerState) => eventStore.set('auxtimer1', state);
|
||||||
const timeNow = () => Date.now();
|
const timeNow = () => Date.now();
|
||||||
|
|
||||||
export const extraTimerService = new ExtraTimerService(emit, timeNow);
|
export const auxTimerService = new AuxTimerService(emit, timeNow);
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { OntimeEvent } from '../core/OntimeEvent.type.js';
|
import type { OntimeEvent } from '../core/OntimeEvent.type.js';
|
||||||
import type { SimpleTimerState } from './ExtraTimer.type.js';
|
import type { SimpleTimerState } from './AuxTimer.type.js';
|
||||||
import type { MessageState } from './MessageControl.type.js';
|
import type { MessageState } from './MessageControl.type.js';
|
||||||
import type { Runtime } from './Runtime.type.js';
|
import type { Runtime } from './Runtime.type.js';
|
||||||
import type { TimerState } from './TimerState.type.js';
|
import type { TimerState } from './TimerState.type.js';
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ export type { RuntimeStore } from './definitions/runtime/RuntimeStore.type.js';
|
|||||||
export type { TimerState } from './definitions/runtime/TimerState.type.js';
|
export type { TimerState } from './definitions/runtime/TimerState.type.js';
|
||||||
|
|
||||||
// ---> Extra Timer
|
// ---> Extra Timer
|
||||||
export { type SimpleTimerState, SimplePlayback, SimpleDirection } from './definitions/runtime/ExtraTimer.type.js';
|
export { type SimpleTimerState, SimplePlayback, SimpleDirection } from './definitions/runtime/AuxTimer.type.js';
|
||||||
|
|
||||||
// CLIENT
|
// CLIENT
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user