45 lines
1.0 KiB
JavaScript
45 lines
1.0 KiB
JavaScript
// 3rd party.
|
|
import React, {useEffect, useState} from 'react';
|
|
// 2nd party.
|
|
import {compose} from '@avocado/core';
|
|
import contempo from 'contempo';
|
|
// 1st party.
|
|
import {WorldTime} from '../../../common/world-time';
|
|
|
|
const decorate = compose(
|
|
contempo(`
|
|
.time {
|
|
background-color: rgba(255, 255, 255, .2);
|
|
box-sizing: border-box;
|
|
border: 1px solid rgba(0, 0, 0, 1);
|
|
color: white;
|
|
position: absolute;
|
|
top: 4px;
|
|
right: 4px;
|
|
padding: 5px;
|
|
font-family: joystix;
|
|
font-size: 6px;
|
|
text-shadow: 0.5px 0.5px 0px black;
|
|
line-height: 4px;
|
|
width: 52px;
|
|
text-align: right;
|
|
}
|
|
`),
|
|
);
|
|
|
|
const WorldTimeComponent = ({worldTime}) => {
|
|
const [time, setTime] = useState('--:-- --');
|
|
useEffect(() => {
|
|
const updater = () => {
|
|
setTime(WorldTime.format(worldTime.hour));
|
|
};
|
|
worldTime.ticker.on('tick', updater);
|
|
return () => {
|
|
worldTime.ticker.off('tick', updater);
|
|
};
|
|
}, []);
|
|
return <div className="time unselectable">{time}</div>;
|
|
}
|
|
|
|
export default decorate(WorldTimeComponent);
|