Files
ontime/client/src/common/components/countdown/Countdown.jsx
T
cv 8e95b06b8c feat: presenter view
- connected to websockets
- some styling changes
- reusable components
- some small bugfixes
2021-04-17 23:54:00 +02:00

33 lines
893 B
React

import { useEffect, useState } from 'react';
import styles from './Countdown.module.css';
function formatDisplay(seconds, hideZero) {
const format = (val) => `0${Math.floor(val)}`.slice(-2);
const hours = seconds / 3600;
const minutes = (seconds % 3600) / 60;
if (hideZero && hours < 1)
return [minutes, seconds % 60].map(format).join(':');
else return [hours, minutes, seconds % 60].map(format).join(':');
}
export default function Countdown(props) {
const { time, small, hideZeroHours } = props;
const [clock, setClock] = useState(time);
let display = '-- : -- : --';
useEffect(() => {
setClock(time);
}, [time]);
// prepare display string
if (clock != null && !isNaN(clock))
display = formatDisplay(clock, hideZeroHours);
return (
<div className={small ? styles.countdownClockSmall : styles.countdownClock}>
{display}
</div>
);
}