mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-21 15:09:10 +00:00
refactor: cap timer values
This commit is contained in:
committed by
Carlos Valente
parent
bb199128aa
commit
119e6caca3
@@ -1,7 +1,14 @@
|
|||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||||
import { isOntimeEvent, MaybeString, OntimeEvent, OntimeRundownEntry, RundownCached } from 'ontime-types';
|
import { isOntimeEvent, MaybeString, OntimeEvent, OntimeRundownEntry, RundownCached } from 'ontime-types';
|
||||||
import { getLinkedTimes, getPreviousEventNormal, reorderArray, swapEventData } from 'ontime-utils';
|
import {
|
||||||
|
dayInMs,
|
||||||
|
getLinkedTimes,
|
||||||
|
getPreviousEventNormal,
|
||||||
|
MILLIS_PER_SECOND,
|
||||||
|
reorderArray,
|
||||||
|
swapEventData,
|
||||||
|
} from 'ontime-utils';
|
||||||
|
|
||||||
import { RUNDOWN } from '../api/constants';
|
import { RUNDOWN } from '../api/constants';
|
||||||
import {
|
import {
|
||||||
@@ -215,9 +222,12 @@ export const useEventAction = () => {
|
|||||||
newValMillis = forgivingStringToMillis(value);
|
newValMillis = forgivingStringToMillis(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// dont allow timer values over 23:59:59
|
||||||
|
const cappedMillis = Math.min(newValMillis, dayInMs - MILLIS_PER_SECOND);
|
||||||
|
|
||||||
const newEvent = {
|
const newEvent = {
|
||||||
id: eventId,
|
id: eventId,
|
||||||
[field]: newValMillis,
|
[field]: cappedMillis,
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
await _updateEventMutation.mutateAsync(newEvent);
|
await _updateEventMutation.mutateAsync(newEvent);
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
import { OntimeEvent, isKeyOfType, isOntimeEvent } from 'ontime-types';
|
import { OntimeEvent, isKeyOfType, isOntimeEvent } from 'ontime-types';
|
||||||
|
import { MILLIS_PER_SECOND } 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,
|
||||||
note: coerceString,
|
note: coerceString,
|
||||||
cue: coerceString,
|
cue: coerceString,
|
||||||
|
|
||||||
duration: (value: unknown) => coerceNumber(value) * 1000,
|
duration: (value: unknown) => Math.max(coerceNumber(value) * MILLIS_PER_SECOND, maxDuration),
|
||||||
|
|
||||||
isPublic: coerceBoolean,
|
isPublic: coerceBoolean,
|
||||||
skip: coerceBoolean,
|
skip: coerceBoolean,
|
||||||
|
|||||||
Reference in New Issue
Block a user