refactor: simplify time-to-end (#828)

* refactor: simplify time-to-end

* refactor: rundown metadata

* refactor: handle overflow in UI

* refactor: show gaps between days

---------

Co-authored-by: Alex Christoffer Rasmussen <ac@omnivox.dk>
This commit is contained in:
Carlos Valente
2024-03-18 17:24:11 +01:00
committed by GitHub
parent 4e6b833e10
commit a91a8a6358
19 changed files with 445 additions and 144 deletions
@@ -66,11 +66,12 @@ export async function addEvent(
const scopedMutation = cache.mutateCache(cache.add);
const { newEvent } = await scopedMutation({ atIndex, event: eventToAdd as OntimeRundownEntry });
notifyChanges({ timer: [newEvent.id], external: true });
// notify runtime that rundown has changed
updateRuntimeOnChange();
// notify timer and external services of change
notifyChanges({ timer: [newEvent.id], external: true });
return newEvent;
}
@@ -82,10 +83,11 @@ export async function deleteEvent(eventId: string) {
const scopedMutation = cache.mutateCache(cache.remove);
await scopedMutation({ eventId });
notifyChanges({ timer: [eventId], external: true });
// notify event loader that rundown has changed
// notify runtime that rundown has changed
updateRuntimeOnChange();
// notify timer and external services of change
notifyChanges({ timer: [eventId], external: true });
}
/**
@@ -115,11 +117,12 @@ export async function editEvent(patch: Partial<OntimeEvent> | Partial<OntimeBloc
// 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 });
// notify event loader that rundown has changed
// notify runtime that rundown has changed
updateRuntimeOnChange();
// notify timer and external services of change
notifyChanges({ timer: [patch.id], external: true });
return newEvent;
}
@@ -132,10 +135,11 @@ export async function batchEditEvents(ids: string[], data: Partial<OntimeEvent>)
const scopedMutation = cache.mutateCache(cache.batchEdit);
await scopedMutation({ patch: data, eventIds: ids });
notifyChanges({ timer: ids, external: true });
// notify event loader that rundown has changed
// notify runtime that rundown has changed
updateRuntimeOnChange();
// notify timer and external services of change
notifyChanges({ timer: ids, external: true });
}
/**
@@ -148,11 +152,12 @@ export async function reorderEvent(eventId: string, from: number, to: number) {
const scopedMutation = cache.mutateCache(cache.reorder);
const reorderedItem = await scopedMutation({ eventId, from, to });
notifyChanges({ timer: true, external: true });
// notify event loader that rundown has changed
// notify runtime that rundown has changed
updateRuntimeOnChange();
// notify timer and external services of change
notifyChanges({ timer: true, external: true });
return reorderedItem;
}
@@ -160,6 +165,10 @@ export async function applyDelay(eventId: string) {
const scopedMutation = cache.mutateCache(cache.applyDelay);
await scopedMutation({ eventId });
// notify runtime that rundown has changed
updateRuntimeOnChange();
// notify timer and external services of change
notifyChanges({ timer: true, external: true });
}
@@ -173,10 +182,11 @@ export async function swapEvents(from: string, to: string) {
const scopedMutation = cache.mutateCache(cache.swap);
await scopedMutation({ fromId: from, toId: to });
notifyChanges({ timer: true, external: true });
// notify event loader that rundown has changed
// notify runtime that rundown has changed
updateRuntimeOnChange();
// notify timer and external services of change
notifyChanges({ timer: true, external: true });
}
/**
@@ -184,8 +194,17 @@ export async function swapEvents(from: string, to: string) {
* Called when we make changes to the rundown object
*/
function updateRuntimeOnChange() {
const playableEvents = getPlayableEvents();
const numEvents = playableEvents.length;
const metadata = cache.getMetadata();
// schedule an update for the end of the event loop
setImmediate(() => updateRundownData(getPlayableEvents()));
setImmediate(() =>
updateRundownData({
numEvents,
...metadata,
}),
);
}
/**
@@ -212,6 +231,11 @@ export function notifyChanges(options: { timer?: boolean | string[]; external?:
*/
export async function initRundown(rundown: OntimeRundown, customFields: CustomFields) {
await cache.init(rundown, customFields);
// notify runtime that rundown has changed
updateRuntimeOnChange();
// notify timer of change
notifyChanges({ timer: true });
}