Skip to content

Commit f2890a3

Browse files
authored
Fix laggy counting (#15)
* Fix laggy counting * Fixed test
1 parent d3a10b7 commit f2890a3

File tree

2 files changed

+1
-12
lines changed

2 files changed

+1
-12
lines changed

src/App.test.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,16 @@ import { makeAdvanceTime } from './utils/test-utils/makeAdvanceTime';
66
import { makeAdvanceDateNowBy } from './utils/test-utils/makeAdvanceDateNowBy';
77
jest.useFakeTimers();
88
const startDate = 1587574443099;
9-
const load = jest.fn();
109
const play = jest.fn();
1110

12-
HTMLMediaElement.prototype.load = load;
1311
HTMLMediaElement.prototype.play = play;
1412
describe('App', () => {
15-
let load;
1613
let play;
1714
afterEach(() => {
1815
cleanup();
1916
});
2017
beforeEach(() => {
21-
load = jest.fn();
2218
play = jest.fn();
23-
HTMLMediaElement.prototype.load = load;
2419
HTMLMediaElement.prototype.play = play;
2520
});
2621
it('should run intervals correctly', () => {
@@ -104,7 +99,6 @@ describe('App', () => {
10499
for (let i = Number(workSecondsValue); i > 0; i--) {
105100
workSecondsCountDown.next(timeLeft.value);
106101
}
107-
expect(load).toHaveBeenCalledTimes(15);
108102
expect(play).toHaveBeenCalledTimes(15);
109103
});
110104
it('should stop interval when clicking button again', () => {
@@ -161,7 +155,6 @@ describe('App', () => {
161155
prepSecondsCountDown.next(timeLeft.value);
162156
}
163157
fireEvent.click(startButton);
164-
expect(load).toHaveBeenCalledTimes(2);
165158
expect(play).toHaveBeenCalledTimes(2);
166159
});
167160
});

src/hooks/useWorkoutTimer.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,8 @@ export function useWorkoutTimer() {
6464
const shouldGetReady =
6565
status === Status.prework || status === Status.break;
6666
if (shouldGetReady) {
67-
beepBreak.load();
6867
beepBreak.play();
6968
} else {
70-
beepWork.load();
7169
beepWork.play();
7270
}
7371
}
@@ -82,23 +80,21 @@ export function useWorkoutTimer() {
8280
statusRef.current === Status.work && roundsLeftRef.current > 0;
8381

8482
if (shouldSwitchToWork) {
85-
beepBreakLong.load();
8683
beepBreakLong.play();
8784
setStatus(Status.work);
8885
setTimeLeft(workInterval);
8986
setRoundsLeft(prevRoundsLeft => prevRoundsLeft - 1);
9087
} else if (shouldSwitchToRest) {
9188
setStatus(Status.break);
9289
setTimeLeft(breakInterval);
93-
beepWorkLong.load();
9490
beepWorkLong.play();
9591
} else {
9692
setStatus(Status.stopped);
9793
clearInterval(interval);
9894
}
9995
}
10096
}
101-
}, 100);
97+
}, 5);
10298
}
10399
return () => {
104100
clearInterval(interval);

0 commit comments

Comments
 (0)