add time in block to restore point (#1192)

This commit is contained in:
Alex Christoffer Rasmussen
2024-08-27 13:08:16 +02:00
committed by GitHub
parent 25aefe322b
commit db5fbd8019
4 changed files with 25 additions and 4 deletions
+6 -1
View File
@@ -11,6 +11,7 @@ export type RestorePoint = {
addedTime: number; addedTime: number;
pausedAt: MaybeNumber; pausedAt: MaybeNumber;
firstStart: MaybeNumber; firstStart: MaybeNumber;
blockStartAt: MaybeNumber;
}; };
/** /**
@@ -45,7 +46,11 @@ export function isRestorePoint(obj: unknown): obj is RestorePoint {
return false; 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; return false;
} }
@@ -14,6 +14,7 @@ describe('isRestorePoint()', () => {
addedTime: 2, addedTime: 2,
pausedAt: 3, pausedAt: 3,
firstStart: 1, firstStart: 1,
blockStartAt: 10,
}; };
expect(isRestorePoint(restorePoint)).toBe(true); expect(isRestorePoint(restorePoint)).toBe(true);
@@ -24,6 +25,7 @@ describe('isRestorePoint()', () => {
addedTime: 0, addedTime: 0,
pausedAt: null, pausedAt: null,
firstStart: 1, firstStart: 1,
blockStartAt: null,
}; };
expect(isRestorePoint(restorePoint)).toBe(true); expect(isRestorePoint(restorePoint)).toBe(true);
}); });
@@ -36,6 +38,7 @@ describe('isRestorePoint()', () => {
startedAt: null, startedAt: null,
addedTime: 0, addedTime: 0,
pausedAt: null, pausedAt: null,
blockStartAt: 10,
}; };
expect(isRestorePoint(restorePoint)).toBe(false); expect(isRestorePoint(restorePoint)).toBe(false);
}); });
@@ -45,6 +48,7 @@ describe('isRestorePoint()', () => {
startedAt: null, startedAt: null,
addedTime: 0, addedTime: 0,
pausedAt: null, pausedAt: null,
blockStartAt: 10,
}; };
expect(isRestorePoint(restorePoint)).toBe(false); expect(isRestorePoint(restorePoint)).toBe(false);
}); });
@@ -55,6 +59,7 @@ describe('isRestorePoint()', () => {
startedAt: 'testing', startedAt: 'testing',
addedTime: 0, addedTime: 0,
pausedAt: null, pausedAt: null,
blockStartAt: 10,
}; };
expect(isRestorePoint(restorePoint)).toBe(false); expect(isRestorePoint(restorePoint)).toBe(false);
}); });
@@ -71,6 +76,7 @@ describe('RestoreService()', () => {
addedTime: 5678, addedTime: 5678,
pausedAt: 9087, pausedAt: 9087,
firstStart: 1234, firstStart: 1234,
blockStartAt: 1652,
}; };
const restoreService = new RestoreService('/path/to/restore/file'); const restoreService = new RestoreService('/path/to/restore/file');
@@ -88,6 +94,7 @@ describe('RestoreService()', () => {
addedTime: 0, addedTime: 0,
pausedAt: null, pausedAt: null,
firstStart: 1234, firstStart: 1234,
blockStartAt: null,
}; };
const restoreService = new RestoreService('/path/to/restore/file'); const restoreService = new RestoreService('/path/to/restore/file');
@@ -105,6 +112,7 @@ describe('RestoreService()', () => {
addedTime: 1234, addedTime: 1234,
pausedAt: 1234, pausedAt: 1234,
firstStart: 1234, firstStart: 1234,
blockStartAt: 10,
}; };
const restoreService = new RestoreService('/path/to/restore/file'); const restoreService = new RestoreService('/path/to/restore/file');
@@ -124,6 +132,7 @@ describe('RestoreService()', () => {
addedTime: 1234, addedTime: 1234,
pausedAt: 1234, pausedAt: 1234,
firstStart: 1234, firstStart: 1234,
blockStartAt: null,
}; };
const restoreService = new RestoreService('/path/to/restore/file'); const restoreService = new RestoreService('/path/to/restore/file');
@@ -755,6 +755,7 @@ function broadcastResult(_target: any, _propertyKey: string, descriptor: Propert
addedTime: state.timer.addedTime, addedTime: state.timer.addedTime,
pausedAt: state._timer.pausedAt, pausedAt: state._timer.pausedAt,
firstStart: state.runtime.actualStart, firstStart: state.runtime.actualStart,
blockStartAt: state.currentBlock.startedAt,
}); });
} }
+9 -3
View File
@@ -194,15 +194,16 @@ export function load(
// patch with potential provided data // patch with potential provided data
if (initialData) { if (initialData) {
patchTimer(initialData); patchTimer(initialData);
const firstStart = initialData?.firstStart; const firstStart = initialData?.firstStart;
if (firstStart === null || typeof firstStart === 'number') { if (firstStart === null || typeof firstStart === 'number') {
runtimeState.runtime.actualStart = firstStart; runtimeState.runtime.actualStart = firstStart;
runtimeState.runtime.offset = getRuntimeOffset(runtimeState); runtimeState.runtime.offset = getRuntimeOffset(runtimeState);
runtimeState.runtime.expectedEnd = getExpectedEnd(runtimeState); runtimeState.runtime.expectedEnd = getExpectedEnd(runtimeState);
} }
if (typeof initialData.blockStartAt === 'number') {
runtimeState.currentBlock.startedAt = initialData.blockStartAt;
}
} }
return event.id === runtimeState.eventNow?.id; return event.id === runtimeState.eventNow?.id;
} }
@@ -680,8 +681,13 @@ function loadBlock(rundown: OntimeRundown) {
const newCurrentBlock = getPreviousBlock(rundown, runtimeState.eventNow.id); 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 // 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; runtimeState.currentBlock.startedAt = null;
} }