mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-21 06:59:09 +00:00
refract
memo
This commit is contained in:
@@ -1,19 +1,15 @@
|
|||||||
import { memo, useEffect, useState } from 'react';
|
import { memo } from 'react';
|
||||||
import { formatDisplay } from '../../dateConfig';
|
import { formatDisplay } from '../../dateConfig';
|
||||||
import styles from './Countdown.module.css';
|
import styles from './Countdown.module.css';
|
||||||
|
|
||||||
const Countdown = ({ time, small, negative, hideZeroHours }) => {
|
const Countdown = ({ time, small, negative, hideZeroHours }) => {
|
||||||
const [clock, setClock] = useState(time);
|
|
||||||
let display = '-- : -- : --';
|
let display = '-- : -- : --';
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setClock(time);
|
|
||||||
}, [time]);
|
|
||||||
|
|
||||||
// prepare display string
|
// prepare display string
|
||||||
if (clock != null && !isNaN(clock))
|
if (time != null && !isNaN(time))
|
||||||
display = formatDisplay(Math.abs(clock), hideZeroHours);
|
display = formatDisplay(Math.abs(time), hideZeroHours);
|
||||||
const colour = negative ? '#ff7597' : '#fffffa';
|
const colour = negative ? '#ff7597' : '#fffffa';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={small ? styles.countdownClockSmall : styles.countdownClock}
|
className={small ? styles.countdownClockSmall : styles.countdownClock}
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import style from './PlaybackControl.module.css';
|
import style from './PlaybackControl.module.css';
|
||||||
import Countdown from '../../common/components/countdown/Countdown';
|
|
||||||
import { stringFromMillis } from '../../common/dateConfig';
|
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useSocket } from '../../app/context/socketContext';
|
import { useSocket } from '../../app/context/socketContext';
|
||||||
import { Button } from '@chakra-ui/button';
|
|
||||||
import PlaybackButtons from './PlaybackButtons';
|
import PlaybackButtons from './PlaybackButtons';
|
||||||
|
import PlaybackTimer from './PlaybackTimer';
|
||||||
|
|
||||||
export default function PlaybackControl() {
|
export default function PlaybackControl() {
|
||||||
const socket = useSocket();
|
const socket = useSocket();
|
||||||
@@ -12,7 +10,6 @@ export default function PlaybackControl() {
|
|||||||
const [timer, setTimer] = useState({
|
const [timer, setTimer] = useState({
|
||||||
clock: null,
|
clock: null,
|
||||||
running: null,
|
running: null,
|
||||||
currentSeconds: null,
|
|
||||||
startedAt: null,
|
startedAt: null,
|
||||||
expectedFinish: null,
|
expectedFinish: null,
|
||||||
});
|
});
|
||||||
@@ -20,7 +17,7 @@ export default function PlaybackControl() {
|
|||||||
|
|
||||||
const resetTimer = () => {
|
const resetTimer = () => {
|
||||||
setTimer({
|
setTimer({
|
||||||
currentSeconds: null,
|
running: null,
|
||||||
startedAt: null,
|
startedAt: null,
|
||||||
expectedFinish: 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 (
|
return (
|
||||||
<div className={style.mainContainer}>
|
<div className={style.mainContainer}>
|
||||||
<div className={style.timeContainer}>
|
<PlaybackTimer
|
||||||
<div className={style.indicators}>
|
timer={timer}
|
||||||
<div className={style.indRoll} />
|
handleIncrement={(amount) => socket.emit('increment-timer', amount)}
|
||||||
<div
|
/>
|
||||||
className={isNegative ? style.indNegativeActive : style.indNegative}
|
|
||||||
/>
|
|
||||||
<div className={style.indDelay} />
|
|
||||||
</div>
|
|
||||||
<div className={style.timer}>
|
|
||||||
<Countdown time={timer?.running} small negative={isNegative} />
|
|
||||||
</div>
|
|
||||||
<div className={style.start}>
|
|
||||||
<span className={style.tag}>Started at </span>
|
|
||||||
<span className={style.time}>{started}</span>
|
|
||||||
</div>
|
|
||||||
<div className={style.finish}>
|
|
||||||
<span className={style.tag}>Finish at </span>
|
|
||||||
<span className={style.time}>{finish}</span>
|
|
||||||
</div>
|
|
||||||
<div className={style.btn}>
|
|
||||||
<Button
|
|
||||||
{...incrementProps}
|
|
||||||
onClick={() => socket.emit('increment-timer', -1)}
|
|
||||||
>
|
|
||||||
-1
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
{...incrementProps}
|
|
||||||
onClick={() => socket.emit('increment-timer', 1)}
|
|
||||||
>
|
|
||||||
+1
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
{...incrementProps}
|
|
||||||
onClick={() => socket.emit('increment-timer', -5)}
|
|
||||||
>
|
|
||||||
-5
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
{...incrementProps}
|
|
||||||
onClick={() => socket.emit('increment-timer', 5)}
|
|
||||||
>
|
|
||||||
+5
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<PlaybackButtons
|
<PlaybackButtons
|
||||||
playback={playback}
|
playback={playback}
|
||||||
selectedId={selectedId}
|
selectedId={selectedId}
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
import style from './PlaybackControl.module.css';
|
||||||
|
import Countdown from '../../common/components/countdown/Countdown';
|
||||||
|
import { stringFromMillis } from '../../common/dateConfig';
|
||||||
|
import { Button } from '@chakra-ui/button';
|
||||||
|
import { memo } from 'react';
|
||||||
|
|
||||||
|
const areEqual = (prevProps, nextProps) => {
|
||||||
|
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 (
|
||||||
|
<>
|
||||||
|
<div className={style.timeContainer}>
|
||||||
|
<div className={style.indicators}>
|
||||||
|
<div className={style.indRoll} />
|
||||||
|
<div
|
||||||
|
className={isNegative ? style.indNegativeActive : style.indNegative}
|
||||||
|
/>
|
||||||
|
<div className={style.indDelay} />
|
||||||
|
</div>
|
||||||
|
<div className={style.timer}>
|
||||||
|
<Countdown time={timer?.running} small negative={isNegative} />
|
||||||
|
</div>
|
||||||
|
<div className={style.start}>
|
||||||
|
<span className={style.tag}>Started at </span>
|
||||||
|
<span className={style.time}>{started}</span>
|
||||||
|
</div>
|
||||||
|
<div className={style.finish}>
|
||||||
|
<span className={style.tag}>Finish at </span>
|
||||||
|
<span className={style.time}>{finish}</span>
|
||||||
|
</div>
|
||||||
|
<div className={style.btn}>
|
||||||
|
<Button {...incrementProps} onClick={() => handleIncrement(-1)}>
|
||||||
|
-1
|
||||||
|
</Button>
|
||||||
|
<Button {...incrementProps} onClick={() => handleIncrement(1)}>
|
||||||
|
+1
|
||||||
|
</Button>
|
||||||
|
<Button {...incrementProps} onClick={() => handleIncrement(-5)}>
|
||||||
|
-5
|
||||||
|
</Button>
|
||||||
|
<Button {...incrementProps} onClick={() => handleIncrement(5)}>
|
||||||
|
+5
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default memo(PlaybackTimer, areEqual);
|
||||||
Reference in New Issue
Block a user