diff --git a/client/src/common/components/countdown/Countdown.jsx b/client/src/common/components/countdown/Countdown.jsx index 87220671c..552294d2a 100644 --- a/client/src/common/components/countdown/Countdown.jsx +++ b/client/src/common/components/countdown/Countdown.jsx @@ -1,19 +1,15 @@ -import { memo, useEffect, useState } from 'react'; +import { memo } from 'react'; import { formatDisplay } from '../../dateConfig'; import styles from './Countdown.module.css'; const Countdown = ({ time, small, negative, hideZeroHours }) => { - const [clock, setClock] = useState(time); let display = '-- : -- : --'; - useEffect(() => { - setClock(time); - }, [time]); - // prepare display string - if (clock != null && !isNaN(clock)) - display = formatDisplay(Math.abs(clock), hideZeroHours); + if (time != null && !isNaN(time)) + display = formatDisplay(Math.abs(time), hideZeroHours); const colour = negative ? '#ff7597' : '#fffffa'; + return (
{ setTimer({ - currentSeconds: null, + running: null, startedAt: null, expectedFinish: null, }); @@ -89,68 +86,12 @@ export default function PlaybackControl() { } }; - const started = stringFromMillis(timer.startedAt, true); - const finish = stringFromMillis(timer.expectedFinish, true); - const isNegative = timer.running < 0; - const isDelayed = false; - const isRolling = false; - - const incrementProps = { - size: 'sm', - width: '2.9em', - colorScheme: 'whiteAlpha', - variant: 'outline', - _focus: { boxShadow: 'none' }, - }; - return (
-
-
-
-
-
-
-
- -
-
- Started at - {started} -
-
- Finish at - {finish} -
-
- - - - -
-
+ socket.emit('increment-timer', amount)} + /> { + return ( + prevProps.timer.running === nextProps.timer.running && + prevProps.timer.expectedFinish === nextProps.timer.expectedFinish && + prevProps.timer.startedAt === nextProps.timer.startedAt + ); +}; + +const PlaybackTimer = ({ timer, handleIncrement }) => { + const started = stringFromMillis(timer.startedAt, true); + const finish = stringFromMillis(timer.expectedFinish, true); + const isNegative = timer.running < 0; + const isDelayed = false; + const isRolling = false; + + const incrementProps = { + size: 'sm', + width: '2.9em', + colorScheme: 'whiteAlpha', + variant: 'outline', + _focus: { boxShadow: 'none' }, + }; + + return ( + <> +
+
+
+
+
+
+
+ +
+
+ Started at + {started} +
+
+ Finish at + {finish} +
+
+ + + + +
+
+ + ); +}; + +export default memo(PlaybackTimer, areEqual);