From db5fbd8019672743d4a565731f4eb0407c42e1c4 Mon Sep 17 00:00:00 2001 From: Alex Christoffer Rasmussen Date: Tue, 27 Aug 2024 13:08:16 +0200 Subject: [PATCH] add time in block to restore point (#1192) --- apps/server/src/services/RestoreService.ts | 7 ++++++- .../src/services/__tests__/RestoreService.test.ts | 9 +++++++++ .../src/services/runtime-service/RuntimeService.ts | 1 + apps/server/src/stores/runtimeState.ts | 12 +++++++++--- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/apps/server/src/services/RestoreService.ts b/apps/server/src/services/RestoreService.ts index 01358eb22..5a7676f38 100644 --- a/apps/server/src/services/RestoreService.ts +++ b/apps/server/src/services/RestoreService.ts @@ -11,6 +11,7 @@ export type RestorePoint = { addedTime: number; pausedAt: MaybeNumber; firstStart: MaybeNumber; + blockStartAt: MaybeNumber; }; /** @@ -45,7 +46,11 @@ export function isRestorePoint(obj: unknown): obj is RestorePoint { return false; } - if (typeof restorePoint.firstStart !== 'number' && restorePoint.pausedAt !== null) { + if (typeof restorePoint.firstStart !== 'number' && restorePoint.firstStart !== null) { + return false; + } + + if (typeof restorePoint.blockStartAt !== 'number' && restorePoint.blockStartAt !== null) { return false; } diff --git a/apps/server/src/services/__tests__/RestoreService.test.ts b/apps/server/src/services/__tests__/RestoreService.test.ts index 9e7859437..cf7e7c911 100644 --- a/apps/server/src/services/__tests__/RestoreService.test.ts +++ b/apps/server/src/services/__tests__/RestoreService.test.ts @@ -14,6 +14,7 @@ describe('isRestorePoint()', () => { addedTime: 2, pausedAt: 3, firstStart: 1, + blockStartAt: 10, }; expect(isRestorePoint(restorePoint)).toBe(true); @@ -24,6 +25,7 @@ describe('isRestorePoint()', () => { addedTime: 0, pausedAt: null, firstStart: 1, + blockStartAt: null, }; expect(isRestorePoint(restorePoint)).toBe(true); }); @@ -36,6 +38,7 @@ describe('isRestorePoint()', () => { startedAt: null, addedTime: 0, pausedAt: null, + blockStartAt: 10, }; expect(isRestorePoint(restorePoint)).toBe(false); }); @@ -45,6 +48,7 @@ describe('isRestorePoint()', () => { startedAt: null, addedTime: 0, pausedAt: null, + blockStartAt: 10, }; expect(isRestorePoint(restorePoint)).toBe(false); }); @@ -55,6 +59,7 @@ describe('isRestorePoint()', () => { startedAt: 'testing', addedTime: 0, pausedAt: null, + blockStartAt: 10, }; expect(isRestorePoint(restorePoint)).toBe(false); }); @@ -71,6 +76,7 @@ describe('RestoreService()', () => { addedTime: 5678, pausedAt: 9087, firstStart: 1234, + blockStartAt: 1652, }; const restoreService = new RestoreService('/path/to/restore/file'); @@ -88,6 +94,7 @@ describe('RestoreService()', () => { addedTime: 0, pausedAt: null, firstStart: 1234, + blockStartAt: null, }; const restoreService = new RestoreService('/path/to/restore/file'); @@ -105,6 +112,7 @@ describe('RestoreService()', () => { addedTime: 1234, pausedAt: 1234, firstStart: 1234, + blockStartAt: 10, }; const restoreService = new RestoreService('/path/to/restore/file'); @@ -124,6 +132,7 @@ describe('RestoreService()', () => { addedTime: 1234, pausedAt: 1234, firstStart: 1234, + blockStartAt: null, }; const restoreService = new RestoreService('/path/to/restore/file'); diff --git a/apps/server/src/services/runtime-service/RuntimeService.ts b/apps/server/src/services/runtime-service/RuntimeService.ts index 950b62b65..7ab29f5ca 100644 --- a/apps/server/src/services/runtime-service/RuntimeService.ts +++ b/apps/server/src/services/runtime-service/RuntimeService.ts @@ -755,6 +755,7 @@ function broadcastResult(_target: any, _propertyKey: string, descriptor: Propert addedTime: state.timer.addedTime, pausedAt: state._timer.pausedAt, firstStart: state.runtime.actualStart, + blockStartAt: state.currentBlock.startedAt, }); } diff --git a/apps/server/src/stores/runtimeState.ts b/apps/server/src/stores/runtimeState.ts index b5cd5ece9..bd748a3f9 100644 --- a/apps/server/src/stores/runtimeState.ts +++ b/apps/server/src/stores/runtimeState.ts @@ -194,15 +194,16 @@ export function load( // patch with potential provided data if (initialData) { patchTimer(initialData); - const firstStart = initialData?.firstStart; if (firstStart === null || typeof firstStart === 'number') { runtimeState.runtime.actualStart = firstStart; runtimeState.runtime.offset = getRuntimeOffset(runtimeState); runtimeState.runtime.expectedEnd = getExpectedEnd(runtimeState); } + if (typeof initialData.blockStartAt === 'number') { + runtimeState.currentBlock.startedAt = initialData.blockStartAt; + } } - return event.id === runtimeState.eventNow?.id; } @@ -680,8 +681,13 @@ function loadBlock(rundown: OntimeRundown) { const newCurrentBlock = getPreviousBlock(rundown, runtimeState.eventNow.id); + // test all block change posibiletys + const formNoBlockToBlock = runtimeState.currentBlock.block === null && newCurrentBlock !== null; + const formBlockToNoBlock = runtimeState.currentBlock.block !== null && newCurrentBlock === null; + const formBlockToNewBlock = runtimeState.currentBlock.block?.id !== newCurrentBlock?.id; + // update time only if the block has changed - if (newCurrentBlock === null || newCurrentBlock.id !== runtimeState.currentBlock.block?.id) { + if (formNoBlockToBlock || formBlockToNoBlock || formBlockToNewBlock) { runtimeState.currentBlock.startedAt = null; }