trigger doRoll if clock is less than startAt

This commit is contained in:
arc-alex
2023-11-20 17:44:39 +01:00
parent afa62a6e38
commit facce4f096
3 changed files with 27 additions and 2 deletions
+1 -1
View File
@@ -339,7 +339,7 @@ export class TimerService {
this.timer.expectedFinish >= this.timer.startedAt this.timer.expectedFinish >= this.timer.startedAt
? this.timer.expectedFinish ? this.timer.expectedFinish
: this.timer.expectedFinish + dayInMs, : this.timer.expectedFinish + dayInMs,
_startAt: this.timer.startedAt,
clock: this.timer.clock, clock: this.timer.clock,
secondaryTimer: this.timer.secondaryTimer, secondaryTimer: this.timer.secondaryTimer,
secondaryTarget: this.secondaryTarget, secondaryTarget: this.secondaryTarget,
@@ -703,4 +703,24 @@ describe('typical scenarios', () => {
expect(updateRoll(timers)).toStrictEqual(expected); expect(updateRoll(timers)).toStrictEqual(expected);
}); });
it('rolls backwards', () => {
const timers = {
selectedEventId: '1',
current: 11,
_startAt: 10,
_finishAt: 15,
clock: 9,
secondaryTimer: null,
secondaryTarget: null,
};
const expected = {
updatedTimer: timers._finishAt - timers.clock,
updatedSecondaryTimer: null,
doRollLoad: true,
isFinished: false,
};
expect(updateRoll(timers)).toStrictEqual(expected);
});
}); });
+6 -1
View File
@@ -153,6 +153,7 @@ type CurrentTimers = {
selectedEventId: string | null; selectedEventId: string | null;
current: number | null; current: number | null;
_finishAt: number | null; _finishAt: number | null;
_startAt: number | null;
clock: number | null; clock: number | null;
secondaryTimer: number | null; secondaryTimer: number | null;
secondaryTarget: number | null; secondaryTarget: number | null;
@@ -164,7 +165,7 @@ type CurrentTimers = {
* @returns {object} object with selection variables * @returns {object} object with selection variables
*/ */
export const updateRoll = (currentTimers: CurrentTimers) => { export const updateRoll = (currentTimers: CurrentTimers) => {
const { selectedEventId, current, _finishAt, clock, secondaryTimer, secondaryTarget } = currentTimers; const { selectedEventId, current, _finishAt, _startAt, clock, secondaryTimer, secondaryTarget } = currentTimers;
// timers // timers
let updatedTimer = current; let updatedTimer = current;
@@ -182,10 +183,14 @@ export const updateRoll = (currentTimers: CurrentTimers) => {
updatedTimer -= dayInMs; updatedTimer -= dayInMs;
} }
console.log(Math.floor(_startAt / 1000), Math.floor(clock / 1000));
if (updatedTimer < 0) { if (updatedTimer < 0) {
isPrimaryFinished = true; isPrimaryFinished = true;
// we need a new event // we need a new event
doRollLoad = true; doRollLoad = true;
} else if (clock < _startAt) {
doRollLoad = true;
} }
} else if (secondaryTimer >= 0) { } else if (secondaryTimer >= 0) {
// if secondaryTimer is running we are in waiting to roll // if secondaryTimer is running we are in waiting to roll