1
+ import { TimerSubState } from '@interval-timer/core' ;
1
2
import { getMinutes , getSeconds } from 'date-fns' ;
2
3
import dynamic from 'next/dynamic' ;
3
4
import * as React from 'react' ;
@@ -23,7 +24,7 @@ type CounterProps = {
23
24
timeTotal : Date ;
24
25
onStop : ( ) => void ;
25
26
onPause : ( ) => void ;
26
- state : string ;
27
+ stateValues : string [ ] ;
27
28
} ;
28
29
29
30
export function Counter ( {
@@ -33,7 +34,7 @@ export function Counter({
33
34
rounds,
34
35
onStop,
35
36
onPause,
36
- state ,
37
+ stateValues ,
37
38
} : CounterProps ) {
38
39
const timeLeftInSeconds =
39
40
getSeconds ( timeLeft ) + getMinutes ( timeLeft ) * SECONDS_PER_MINUTE ;
@@ -46,6 +47,8 @@ export function Counter({
46
47
47
48
const stepLength = 1 - timeLeftAdvancedByOneInSeconds / timeTotalInSeconds ;
48
49
50
+ const [ parentState , childState ] = stateValues ;
51
+
49
52
const counterDesktop = (
50
53
< div className = "h-full w-full lg:max-w-screen-xl hidden lg:flex justify-between flex-col items-center" >
51
54
< div className = "w-full flex" >
@@ -66,7 +69,7 @@ export function Counter({
66
69
</ div >
67
70
< div className = "flex flex-col justify-center items-center" >
68
71
< Arc
69
- key = { state }
72
+ key = { parentState }
70
73
className = "absolute origin-center"
71
74
progress = { factor * 100 }
72
75
progressPerSecond = { stepLength * 100 }
@@ -87,7 +90,7 @@ export function Counter({
87
90
className = "text-white bg-blue-600 text-2xl 2xl:text-3xl px-12 h-16 2xl:h-20 rounded-full tracking-widest ml-4"
88
91
onClick = { onPause }
89
92
>
90
- PAUSE
93
+ { childState . endsWith ( TimerSubState . RUNNING ) ? ' PAUSE' : 'RESUME' }
91
94
</ button >
92
95
</ div >
93
96
</ div >
@@ -115,7 +118,7 @@ export function Counter({
115
118
</ div >
116
119
< div className = "flex flex-col justify-center items-center relative w-72 h-72 mb-16" >
117
120
< Arc
118
- key = { state }
121
+ key = { parentState }
119
122
className = "absolute origin-center"
120
123
progress = { factor * 100 }
121
124
progressPerSecond = { stepLength * 100 }
@@ -139,7 +142,7 @@ export function Counter({
139
142
className = "text-white bg-blue-600 text-2xl px-12 h-14 rounded-full tracking-widest ml-4"
140
143
onClick = { onPause }
141
144
>
142
- PAUSE
145
+ { childState . endsWith ( TimerSubState . RUNNING ) ? ' PAUSE' : 'RESUME' }
143
146
</ button >
144
147
</ div >
145
148
</ div >
0 commit comments