mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-05 22:39:11 +00:00
refactor: cap added time
This commit is contained in:
committed by
Carlos Valente
parent
d05cc88748
commit
7cefe07594
@@ -2,7 +2,7 @@ import { Tooltip } from '@chakra-ui/react';
|
|||||||
import { IoAdd } from '@react-icons/all-files/io5/IoAdd';
|
import { IoAdd } from '@react-icons/all-files/io5/IoAdd';
|
||||||
import { IoRemove } from '@react-icons/all-files/io5/IoRemove';
|
import { IoRemove } from '@react-icons/all-files/io5/IoRemove';
|
||||||
import { Playback } from 'ontime-types';
|
import { Playback } from 'ontime-types';
|
||||||
import { MILLIS_PER_SECOND } from 'ontime-utils';
|
import { MILLIS_PER_HOUR, MILLIS_PER_SECOND } from 'ontime-utils';
|
||||||
|
|
||||||
import TimeInput from '../../../../common/components/input/time-input/TimeInput';
|
import TimeInput from '../../../../common/components/input/time-input/TimeInput';
|
||||||
import { useLocalStorage } from '../../../../common/hooks/useLocalStorage';
|
import { useLocalStorage } from '../../../../common/hooks/useLocalStorage';
|
||||||
@@ -23,7 +23,8 @@ export default function AddTime(props: AddTimeProps) {
|
|||||||
|
|
||||||
const handleTimeChange = (_field: string, value: string) => {
|
const handleTimeChange = (_field: string, value: string) => {
|
||||||
const newTime = forgivingStringToMillis(value);
|
const newTime = forgivingStringToMillis(value);
|
||||||
setTime(newTime);
|
// cap add time to 1 hour
|
||||||
|
setTime(Math.min(newTime, MILLIS_PER_HOUR));
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAddTime = (direction: 'add' | 'remove') => {
|
const handleAddTime = (direction: 'add' | 'remove') => {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { DeepPartial, MessageState, OntimeEvent, SimpleDirection, SimplePlayback } from 'ontime-types';
|
import { DeepPartial, MessageState, OntimeEvent, SimpleDirection, SimplePlayback } from 'ontime-types';
|
||||||
|
import { MILLIS_PER_HOUR, MILLIS_PER_SECOND } from 'ontime-utils';
|
||||||
|
|
||||||
import { ONTIME_VERSION } from '../ONTIME_VERSION.js';
|
import { ONTIME_VERSION } from '../ONTIME_VERSION.js';
|
||||||
import { auxTimerService } from '../services/aux-timer-service/AuxTimerService.js';
|
import { auxTimerService } from '../services/aux-timer-service/AuxTimerService.js';
|
||||||
@@ -177,7 +178,13 @@ const actionHandlers: Record<string, ActionHandler> = {
|
|||||||
if (time === 0) {
|
if (time === 0) {
|
||||||
return { payload: 'success' };
|
return { payload: 'success' };
|
||||||
}
|
}
|
||||||
runtimeService.addTime(time * 1000); //frontend is seconds based
|
|
||||||
|
const timeToAdd = time * MILLIS_PER_SECOND; // frontend is seconds based
|
||||||
|
if (Math.abs(timeToAdd) > MILLIS_PER_HOUR) {
|
||||||
|
throw new Error(`Payload too large: ${time}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
runtimeService.addTime(timeToAdd);
|
||||||
return { payload: 'success' };
|
return { payload: 'success' };
|
||||||
},
|
},
|
||||||
/* Extra timers */
|
/* Extra timers */
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import { OntimeEvent, isKeyOfType, isOntimeEvent } from 'ontime-types';
|
import { OntimeEvent, isKeyOfType, isOntimeEvent } from 'ontime-types';
|
||||||
import { MILLIS_PER_SECOND } from 'ontime-utils';
|
import { MILLIS_PER_SECOND, maxDuration } from 'ontime-utils';
|
||||||
|
|
||||||
import { DataProvider } from '../classes/data-provider/DataProvider.js';
|
import { DataProvider } from '../classes/data-provider/DataProvider.js';
|
||||||
import { editEvent } from '../services/rundown-service/RundownService.js';
|
import { editEvent } from '../services/rundown-service/RundownService.js';
|
||||||
import { getEventWithId } from '../services/rundown-service/rundownUtils.js';
|
import { getEventWithId } from '../services/rundown-service/rundownUtils.js';
|
||||||
import { coerceBoolean, coerceColour, coerceNumber, coerceString } from '../utils/coerceType.js';
|
import { coerceBoolean, coerceColour, coerceNumber, coerceString } from '../utils/coerceType.js';
|
||||||
import { maxDuration } from '../../../../packages/utils/src/date-utils/conversionUtils.js';
|
|
||||||
|
|
||||||
const whitelistedPayload = {
|
const whitelistedPayload = {
|
||||||
title: coerceString,
|
title: coerceString,
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export {
|
|||||||
// time format utils
|
// time format utils
|
||||||
export {
|
export {
|
||||||
dayInMs,
|
dayInMs,
|
||||||
|
maxDuration,
|
||||||
MILLIS_PER_HOUR,
|
MILLIS_PER_HOUR,
|
||||||
MILLIS_PER_MINUTE,
|
MILLIS_PER_MINUTE,
|
||||||
MILLIS_PER_SECOND,
|
MILLIS_PER_SECOND,
|
||||||
|
|||||||
Reference in New Issue
Block a user