mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-14 20:03:52 +00:00
refactor: small type improvements (#759)
This commit is contained in:
@@ -81,7 +81,7 @@ export class TimerService {
|
||||
const newState = runtimeState.getState();
|
||||
|
||||
// handle end action if there was a timer playing
|
||||
if (newState.timer.playback === Playback.Play) {
|
||||
if (newState.timer.playback === Playback.Play && newState.eventNow) {
|
||||
if (newState.eventNow.endAction === EndAction.Stop) {
|
||||
runtimeState.stop();
|
||||
} else if (newState.eventNow.endAction === EndAction.LoadNext) {
|
||||
|
||||
@@ -860,7 +860,7 @@ describe('getRollTimers()', () => {
|
||||
publicIndex: null,
|
||||
nextIndex: 0,
|
||||
publicNextIndex: 4,
|
||||
timeToNext: dayInMs - now + eventlist[0].timeStart,
|
||||
timeToNext: dayInMs - now + eventlist[0].timeStart!,
|
||||
nextEvent: eventlist[0],
|
||||
nextPublicEvent: eventlist[4],
|
||||
currentEvent: null,
|
||||
@@ -887,7 +887,7 @@ describe('getRollTimers()', () => {
|
||||
publicIndex: null,
|
||||
nextIndex: 0,
|
||||
publicNextIndex: 0,
|
||||
timeToNext: dayInMs - now + singleEventList[0].timeStart,
|
||||
timeToNext: dayInMs - now + singleEventList[0].timeStart!,
|
||||
nextEvent: singleEventList[0],
|
||||
nextPublicEvent: singleEventList[0],
|
||||
currentEvent: null,
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { MaybeNumber } from 'ontime-types';
|
||||
import { millisToString, removeLeadingZero } from 'ontime-utils';
|
||||
|
||||
// any value inside double curly braces {{val}}
|
||||
const placeholderRegex = /{{(.*?)}}/g;
|
||||
|
||||
function formatDisplayFromString(value: string, hideZero = false): string {
|
||||
let valueInNumber = null;
|
||||
let valueInNumber: MaybeNumber = null;
|
||||
|
||||
if (value !== 'null') {
|
||||
const parsedValue = Number(value);
|
||||
@@ -48,7 +49,7 @@ export function parseTemplateNested(template: string, state: object, humanReadab
|
||||
for (const match of matches) {
|
||||
const variableName = match[1];
|
||||
const variableParts = variableName.split('.');
|
||||
let value = undefined;
|
||||
let value: string | undefined = undefined;
|
||||
|
||||
if (variableParts[0] === 'human') {
|
||||
const lookupKey = variableParts[1];
|
||||
|
||||
@@ -4,7 +4,7 @@ import { throttle } from '../../utils/throttle.js';
|
||||
|
||||
import type { PublishFn } from '../../stores/EventStore.js';
|
||||
|
||||
let instance;
|
||||
let instance: MessageService | null = null;
|
||||
|
||||
class MessageService {
|
||||
timer: TimerMessage;
|
||||
@@ -56,7 +56,7 @@ class MessageService {
|
||||
|
||||
init(publish: PublishFn) {
|
||||
this.publish = publish;
|
||||
this.throttledSet = throttle((key, value) => this.publish(key, value), 100);
|
||||
this.throttledSet = throttle((key, value) => this.publish?.(key, value), 100);
|
||||
}
|
||||
|
||||
getState(): MessageState {
|
||||
|
||||
@@ -104,7 +104,8 @@ export async function editEvent(patch: Partial<OntimeEvent> | Partial<OntimeBloc
|
||||
}
|
||||
|
||||
const scopedMutation = cache.mutateCache(cache.edit);
|
||||
const { newEvent } = await scopedMutation({ patch, eventId: patch.id });
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- we know patch has an id
|
||||
const { newEvent } = await scopedMutation({ patch, eventId: patch.id! });
|
||||
|
||||
notifyChanges({ timer: [patch.id], external: true });
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ export function get(): Readonly<RundownCache> {
|
||||
}
|
||||
|
||||
type CommonParams = { persistedRundown: OntimeRundown };
|
||||
type MutationParams<T> = T & Partial<CommonParams>;
|
||||
type MutationParams<T> = T & CommonParams;
|
||||
type MutatingReturn = {
|
||||
newRundown: OntimeRundown;
|
||||
newEvent?: OntimeRundownEntry;
|
||||
|
||||
@@ -166,6 +166,9 @@ class RuntimeService {
|
||||
*/
|
||||
startById(eventId: string): boolean {
|
||||
const event = getEventWithId(eventId);
|
||||
if (!event) {
|
||||
return false;
|
||||
}
|
||||
const success = this.loadEvent(event);
|
||||
if (success) {
|
||||
this.start();
|
||||
@@ -180,6 +183,9 @@ class RuntimeService {
|
||||
*/
|
||||
startByIndex(eventIndex: number): boolean {
|
||||
const event = getEventAtIndex(eventIndex);
|
||||
if (!event) {
|
||||
return false;
|
||||
}
|
||||
const success = this.loadEvent(event);
|
||||
if (success) {
|
||||
this.start();
|
||||
@@ -194,6 +200,9 @@ class RuntimeService {
|
||||
*/
|
||||
startByCue(cue: string): boolean {
|
||||
const event = getEventWithCue(cue);
|
||||
if (!event) {
|
||||
return false;
|
||||
}
|
||||
const success = this.loadEvent(event);
|
||||
if (success) {
|
||||
this.start();
|
||||
@@ -208,6 +217,9 @@ class RuntimeService {
|
||||
*/
|
||||
loadById(eventId: string): boolean {
|
||||
const event = getEventWithId(eventId);
|
||||
if (!event) {
|
||||
return false;
|
||||
}
|
||||
const success = this.loadEvent(event);
|
||||
return success;
|
||||
}
|
||||
@@ -219,6 +231,9 @@ class RuntimeService {
|
||||
*/
|
||||
loadByIndex(eventIndex: number): boolean {
|
||||
const event = getEventAtIndex(eventIndex);
|
||||
if (!event) {
|
||||
return false;
|
||||
}
|
||||
const success = this.loadEvent(event);
|
||||
return success;
|
||||
}
|
||||
@@ -230,6 +245,9 @@ class RuntimeService {
|
||||
*/
|
||||
loadByCue(cue: string): boolean {
|
||||
const event = getEventWithCue(cue);
|
||||
if (!event) {
|
||||
return false;
|
||||
}
|
||||
const success = this.loadEvent(event);
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,11 @@ export const normaliseEndTime = (start: number, end: number) => (end < start ? e
|
||||
*/
|
||||
export function getExpectedFinish(state: RuntimeState): MaybeNumber {
|
||||
const { startedAt, finishedAt, duration, addedTime } = state.timer;
|
||||
|
||||
if (state.eventNow === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { timerType, timeEnd } = state.eventNow;
|
||||
const { pausedAt } = state._timer;
|
||||
const { clock } = state;
|
||||
@@ -33,7 +38,8 @@ export function getExpectedFinish(state: RuntimeState): MaybeNumber {
|
||||
}
|
||||
|
||||
// handle events that finish the day after
|
||||
const expectedFinish = startedAt + duration + addedTime + pausedTime;
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- duration exists if ther eis a timer
|
||||
const expectedFinish = startedAt + duration! + addedTime + pausedTime;
|
||||
if (expectedFinish > dayInMs) {
|
||||
return expectedFinish - dayInMs;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user