Fix current block (#1170)

* pass full rundown to loadNow

* remove prevBlock from state

* refactor: simplify load logic (#1174)

* send clock to client on block start to avoid it showing -1 in the client

---------

Co-authored-by: Carlos Valente <34649812+cpvalente@users.noreply.github.com>
This commit is contained in:
Alex Christoffer Rasmussen
2024-08-15 16:25:29 +02:00
committed by GitHub
parent 49467c66b7
commit f708dc0bc4
3 changed files with 46 additions and 24 deletions
@@ -303,20 +303,21 @@ export function getEventWithId(rundown: OntimeRundown, id: string): OntimeRundow
* Gets relevant block element for a given ID
*/
export function getRelevantBlock(rundown: OntimeRundown, currentId: string): OntimeBlock | null {
let inBlock = false;
let foundCurrentEvent = false;
// Iterate backwards through the rundown to find the current event
for (let i = rundown.length - 1; i >= 0; i--) {
const entry = rundown[i];
if (entry.id === currentId) {
//set the flag when the current event is found
inBlock = true;
if (!foundCurrentEvent && entry.id === currentId) {
// set the flag when the current event is found
foundCurrentEvent = true;
continue;
}
//the first block before the current event is the relevant one
if (inBlock && isOntimeBlock(entry)) {
// the first block before the current event is the relevant one
if (foundCurrentEvent && isOntimeBlock(entry)) {
return entry;
}
}
//no blocks exist before current event
// no blocks exist before current event
return null;
}