refactor: export rundown placement logic

This commit is contained in:
Carlos Valente
2026-02-11 21:16:31 +01:00
committed by Carlos Valente
parent 7c5fdd3b19
commit 80a3b04493
7 changed files with 194 additions and 119 deletions
@@ -483,31 +483,6 @@ export function calculateDayOffset(
return 0;
}
/**
* Receives an insertion order and returns the reference to an event ID
* after which we will insert the new event
*/
export function getInsertAfterId(
rundown: Rundown,
parent: OntimeGroup | null,
afterId?: EntryId,
beforeId?: EntryId,
): EntryId | null {
if (afterId) return afterId;
if (!beforeId) return null;
/**
* At this point we know we want to insert before a given ID
* We need to check which list we should use to insert and find the event there
*/
const insertionList = parent ? parent.entries : rundown.order;
if (!insertionList || insertionList.length === 0) return null;
const atIndex = insertionList.findIndex((id) => id === beforeId);
if (atIndex < 1) return null;
return insertionList[atIndex - 1];
}
/**
* Sanitises custom fields in an entry by removing fields
* - if it does not exist in the project