@@ -72,6 +72,8 @@ function App(props) {
72
72
const [ timerType , setTimerType ] = useState ( new TimerType ( "work" ) ) ;
73
73
const [ duration , setDuration ] = useState ( timerType . duration ( config ) ) ;
74
74
75
+ const [ paused , setPaused ] = useState ( false ) ;
76
+
75
77
// timer worker (runs in background)
76
78
const worker = useMemo ( ( ) => {
77
79
let worker = buildWorker ( TimerWorker ) ;
@@ -100,17 +102,20 @@ function App(props) {
100
102
101
103
const play = ( ) => {
102
104
setTimerStart ( performance . now ( ) ) ;
105
+ setPaused ( false ) ;
103
106
} ;
104
107
105
108
const pause = ( ) => {
106
109
setTimerStart ( undefined ) ;
107
110
setDuration ( duration - elapsed ) ;
108
111
setElapsed ( 0 ) ;
112
+ setPaused ( true ) ;
109
113
} ;
110
114
111
115
const restart = ( ) => {
112
116
setDuration ( timerType . duration ( config ) ) ;
113
117
if ( isPlaying ( ) ) setTimerStart ( performance . now ( ) ) ;
118
+ setPaused ( false ) ;
114
119
} ;
115
120
116
121
const timerFinish = useCallback ( ( ) => {
@@ -156,8 +161,8 @@ function App(props) {
156
161
157
162
// update timer duration if config is updated and timer is not running
158
163
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 ] ) ;
161
166
162
167
let playing = isPlaying ( ) ;
163
168
return (
0 commit comments