Skip to content

Commit

Permalink
Update timer design
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir-Urik committed Jun 28, 2024
1 parent dcff638 commit 280bfec
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/components/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,33 @@ export function Game({ setGradient }: GameProps) {
}

const startTimer = () => {
setTimeToReset(3)
setTimeToReset(3000)
const timer = setInterval(() => {
setTimeToReset((prev) => {
if (prev < 1) {
if (prev < 10) {
clearInterval(timer)
return 0
}
return prev - 1
return prev - 10
})
}, 1000)
}, 10)
}

const getRemainingPercentage = () => {
return (timeToReset / 3) * 100
return (timeToReset / 3000) * 100
}

const getColor = () => {
const percentage = getRemainingPercentage()
if (percentage < 33) {
return 'stroke-green-500'
}

if (percentage < 66) {
return 'stroke-yellow-500'
}

return 'stroke-red-500'
}

return (
Expand Down Expand Up @@ -130,17 +143,18 @@ export function Game({ setGradient }: GameProps) {
cy="18"
r="16"
fill="none"
className="stroke-current text-yellow-300"
className={'stroke-current transition-colors ' + getColor()}
strokeWidth="3"
strokeDasharray="100"
strokeLinecap={'round'}
strokeDashoffset={getRemainingPercentage()}
></circle>
</g>
</svg>

<div className="absolute start-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2">
<span className="text-center text-3xl font-bold text-gray-800 dark:text-white">
{timeToReset}
{Math.round(timeToReset / 1000)}
</span>
</div>
</div>
Expand All @@ -165,7 +179,7 @@ export function Game({ setGradient }: GameProps) {
<button
disabled={timeToReset > 0}
className={
'w-fit rounded-lg bg-black px-8 py-4 font-bold text-white disabled:opacity-50'
'w-fit rounded-lg bg-black px-8 py-4 font-bold text-white disabled:opacity-30'
}
onClick={() => change()}
>
Expand Down

0 comments on commit 280bfec

Please sign in to comment.