2019-10-31 15:40:34 +01:00
|
|
|
import { useSelector, shallowEqual } from 'react-redux'
|
|
|
|
|
|
|
|
const useClock = () => {
|
|
|
|
return useSelector(
|
2020-05-18 21:24:37 +02:00
|
|
|
(state) => ({
|
2019-10-31 15:40:34 +01:00
|
|
|
lastUpdate: state.lastUpdate,
|
2019-11-11 04:24:53 +01:00
|
|
|
light: state.light,
|
2019-10-31 15:40:34 +01:00
|
|
|
}),
|
|
|
|
shallowEqual
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-05-18 21:24:37 +02:00
|
|
|
const formatTime = (time) => {
|
2019-10-31 15:40:34 +01:00
|
|
|
// cut off except hh:mm:ss
|
|
|
|
return new Date(time).toJSON().slice(11, 19)
|
|
|
|
}
|
|
|
|
|
|
|
|
const Clock = () => {
|
|
|
|
const { lastUpdate, light } = useClock()
|
2018-01-31 10:40:32 +01:00
|
|
|
return (
|
|
|
|
<div className={light ? 'light' : ''}>
|
2019-10-31 15:40:34 +01:00
|
|
|
{formatTime(lastUpdate)}
|
2018-01-31 10:40:32 +01:00
|
|
|
<style jsx>{`
|
|
|
|
div {
|
|
|
|
padding: 15px;
|
|
|
|
display: inline-block;
|
2018-12-17 17:34:32 +01:00
|
|
|
color: #82fa58;
|
2018-01-31 10:40:32 +01:00
|
|
|
font: 50px menlo, monaco, monospace;
|
|
|
|
background-color: #000;
|
|
|
|
}
|
|
|
|
.light {
|
|
|
|
background-color: #999;
|
|
|
|
}
|
|
|
|
`}</style>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-10-31 15:40:34 +01:00
|
|
|
export default Clock
|