Skip to content

Commit 550800e

Browse files
authored
Merge pull request #15 from asherhe/dev
fix issue where timer reset on pause
2 parents 0bc3b6d + 6c5f4bd commit 550800e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/components/app.jsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ function App(props) {
7272
const [timerType, setTimerType] = useState(new TimerType("work"));
7373
const [duration, setDuration] = useState(timerType.duration(config));
7474

75+
const [paused, setPaused] = useState(false);
76+
7577
// timer worker (runs in background)
7678
const worker = useMemo(() => {
7779
let worker = buildWorker(TimerWorker);
@@ -100,17 +102,20 @@ function App(props) {
100102

101103
const play = () => {
102104
setTimerStart(performance.now());
105+
setPaused(false);
103106
};
104107

105108
const pause = () => {
106109
setTimerStart(undefined);
107110
setDuration(duration - elapsed);
108111
setElapsed(0);
112+
setPaused(true);
109113
};
110114

111115
const restart = () => {
112116
setDuration(timerType.duration(config));
113117
if (isPlaying()) setTimerStart(performance.now());
118+
setPaused(false);
114119
};
115120

116121
const timerFinish = useCallback(() => {
@@ -156,8 +161,8 @@ function App(props) {
156161

157162
// update timer duration if config is updated and timer is not running
158163
useEffect(() => {
159-
if (!isPlaying()) setDuration(timerType.duration(config));
160-
}, [config, isPlaying, timerType]);
164+
if (!isPlaying() && !paused) setDuration(timerType.duration(config));
165+
}, [config, isPlaying, timerType, paused]);
161166

162167
let playing = isPlaying();
163168
return (

0 commit comments

Comments
 (0)