-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathTimerDisplay.tsx
More file actions
188 lines (179 loc) · 5.01 KB
/
Copy pathTimerDisplay.tsx
File metadata and controls
188 lines (179 loc) · 5.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// File: components/TimerDisplay.tsx
'use client'
import Box from '@mui/material/Box'
import Card from '@mui/material/Card'
import CardContent from '@mui/material/CardContent'
import Typography from '@mui/material/Typography'
import { memo } from 'react'
import { useTimerData } from '@/hooks/useTimerData'
const pad = (n: number) => String(n).padStart(2, '0')
const TimerDisplay = () => {
const {
phase,
timeRemaining,
timeElapsed,
mode,
workDuration = 20,
restDuration = 10,
} = useTimerData()
// Determine what to display based on mode and phase
let displayTime: string
let phaseColor: string
let phaseLabel: string
if (phase === 'PREPARE') {
// PREPARE: Show countdown seconds only
displayTime = String(timeRemaining).padStart(2, '0')
phaseColor = '#F59E0B' // Yellow/Warning
phaseLabel = 'GET READY'
} else if (mode === 'STOPWATCH' && phase === 'RUNNING') {
// STOPWATCH: Show elapsed time MM:SS
const mm = Math.floor(timeElapsed / 60)
const ss = timeElapsed % 60
displayTime = `${pad(mm)}:${pad(ss)}`
phaseColor = '#2563EB' // Blue/Primary
phaseLabel = 'RUNNING'
} else if (
mode === 'TABATA' &&
(phase === 'WORK' || phase === 'REST' || phase === 'COOLDOWN')
) {
// TABATA: Show remaining time MM:SS
const mm = Math.floor(timeRemaining / 60)
const ss = timeRemaining % 60
displayTime = `${pad(mm)}:${pad(ss)}`
if (phase === 'WORK') {
phaseColor = '#EF4444' // Red
phaseLabel = 'WORK'
} else if (phase === 'REST') {
phaseColor = '#22C55E' // Green
phaseLabel = 'REST'
} else {
phaseColor = '#3B82F6' // Blue
phaseLabel = 'COOLDOWN'
}
} else {
// IDLE or default
displayTime = '00:00'
phaseColor = '#6B7280' // Gray
phaseLabel = 'READY'
}
return (
<Card
elevation={6}
sx={{
backgroundColor: '#000000', // Pure black for high energy
color: phaseColor, // Dynamic color based on phase
height: '100%',
display: 'flex',
borderRadius: 2,
border: '2px solid #1a1a1a', // Subtle border for definition
position: 'relative',
}}
>
{/* Mode Indicator - Rotated on left side */}
{phase !== 'IDLE' && (
<Box
sx={{
position: 'absolute',
left: 16,
top: '50%',
transform: 'translateY(-50%) rotate(-90deg)',
transformOrigin: 'center',
zIndex: 1,
}}
>
<Typography
variant="body2"
sx={{
color: '#fff',
fontWeight: 700,
letterSpacing: 2,
whiteSpace: 'nowrap',
fontSize: '0.9rem',
backgroundColor: 'rgba(255,255,255,0.1)',
px: 1,
py: 0.5,
borderRadius: 1,
}}
>
{mode === 'STOPWATCH' ? 'STOPWATCH' : 'TABATA'}
</Typography>
</Box>
)}
{/* Tabata Durations - Rotated on right side */}
{mode === 'TABATA' && (
<Box
sx={{
position: 'absolute',
right: 16,
top: '50%',
transform: 'translateY(-50%) rotate(90deg)',
transformOrigin: 'center',
zIndex: 1,
}}
>
<Typography
variant="body2"
sx={{
color: '#fff',
fontWeight: 700,
letterSpacing: 1,
whiteSpace: 'nowrap',
fontSize: '0.8rem',
backgroundColor: 'rgba(255,255,255,0.1)',
px: 1,
py: 0.5,
borderRadius: 1,
}}
>
WORK:{workDuration}s REST:{restDuration}s
</Typography>
</Box>
)}
<CardContent
sx={{
p: { xs: 2, md: 3 },
textAlign: 'center',
flex: 1,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
}}
>
{/* Phase Label - only show for Tabata phases, not RUNNING */}
{phase !== 'IDLE' && phase !== 'RUNNING' && (
<Typography
variant="h6"
sx={{
mb: 1,
color: phaseColor,
fontWeight: 700,
letterSpacing: 2,
}}
>
{phaseLabel}
</Typography>
)}
{/* Giant Timer Display */}
<Typography
component="div"
role="timer"
aria-live="polite"
aria-atomic="true"
sx={{
fontFamily: 'var(--font-roboto-mono), monospace',
fontSize: { xs: '6rem', sm: '8rem', md: '10rem' },
fontWeight: 800,
letterSpacing: '0.12rem',
lineHeight: 1,
color: phaseColor,
textShadow: `0 0 20px ${phaseColor}80`,
}}
>
{displayTime}
</Typography>
</CardContent>
</Card>
)
}
export default memo(TimerDisplay)