|
@@ -3,9 +3,10 @@ import React, { useEffect } from 'react';
|
|
|
import s from './TimerPresentation.module.css';
|
|
|
interface ITimerPresentationProps {
|
|
|
seconds: number;
|
|
|
+ refresh: number;
|
|
|
}
|
|
|
|
|
|
-const TimerPresentation = ({ seconds }: ITimerPresentationProps) => {
|
|
|
+const TimerPresentation = ({ seconds, refresh }: ITimerPresentationProps) => {
|
|
|
useEffect(() => {
|
|
|
function setRotation(el: HTMLDivElement, rotationRatio: number) {
|
|
|
el.style.setProperty('--rotation', String(rotationRatio * 360));
|
|
@@ -20,18 +21,17 @@ const TimerPresentation = ({ seconds }: ITimerPresentationProps) => {
|
|
|
'[data-second-hand]',
|
|
|
) as HTMLDivElement;
|
|
|
function setClock() {
|
|
|
- const currentDate = new Date(seconds);
|
|
|
- const secondsRatio = currentDate.getSeconds() / 60;
|
|
|
- const minutesRatio = (secondsRatio + currentDate.getMinutes()) / 60;
|
|
|
- const hoursRatio = (minutesRatio + currentDate.getHours()) / 12;
|
|
|
+ const secondsRatio = seconds / 60;
|
|
|
+ const minutesRatio = (secondsRatio + secondsRatio) / 60;
|
|
|
+ const hoursRatio = (minutesRatio + secondsRatio / 12) / 12;
|
|
|
setRotation(secondHand, secondsRatio);
|
|
|
setRotation(minuteHand, minutesRatio);
|
|
|
setRotation(hourHand, hoursRatio);
|
|
|
}
|
|
|
setClock();
|
|
|
- const idInterval = setInterval(setClock, 1000);
|
|
|
+ const idInterval = setInterval(setClock, refresh);
|
|
|
return () => clearInterval(idInterval);
|
|
|
- }, [seconds]);
|
|
|
+ }, [seconds, refresh]);
|
|
|
|
|
|
return (
|
|
|
<div className={s.clock}>
|