From bd677163ed44b856b7b05b1aec3ef231e8290daf Mon Sep 17 00:00:00 2001
From: cv <34649812+cpvalente@users.noreply.github.com>
Date: Mon, 10 May 2021 22:55:23 +0200
Subject: [PATCH] refract
memo
---
.../common/components/countdown/Countdown.jsx | 12 ++--
.../src/features/control/PlaybackControl.jsx | 71 ++-----------------
client/src/features/control/PlaybackTimer.jsx | 70 ++++++++++++++++++
3 files changed, 80 insertions(+), 73 deletions(-)
create mode 100644 client/src/features/control/PlaybackTimer.jsx
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);