2021-05-14 18:51:56 +02:00
|
|
|
import { useEffect } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
2021-05-15 18:05:53 +02:00
|
|
|
import { Skycons } from 'skycons-ts';
|
2021-05-14 18:51:56 +02:00
|
|
|
import { GlobalState, Theme } from '../../../../interfaces';
|
2021-05-15 18:05:53 +02:00
|
|
|
import { IconMapping, TimeOfDay } from './IconMapping';
|
2021-05-14 18:51:56 +02:00
|
|
|
|
|
|
|
interface ComponentProps {
|
|
|
|
theme: Theme;
|
2021-05-15 18:05:53 +02:00
|
|
|
weatherStatusCode: number;
|
2021-05-14 18:51:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const WeatherIcon = (props: ComponentProps): JSX.Element => {
|
2021-05-15 18:05:53 +02:00
|
|
|
const icon = (new IconMapping).mapIcon(props.weatherStatusCode, TimeOfDay.day);
|
|
|
|
|
2021-05-14 18:51:56 +02:00
|
|
|
useEffect(() => {
|
|
|
|
const delay = setTimeout(() => {
|
|
|
|
const skycons = new Skycons({'color': props.theme.colors.accent});
|
2021-05-15 18:05:53 +02:00
|
|
|
skycons.add(`weather-icon`, icon);
|
2021-05-14 18:51:56 +02:00
|
|
|
skycons.play();
|
|
|
|
}, 1);
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
clearTimeout(delay);
|
|
|
|
}
|
|
|
|
}, []);
|
|
|
|
|
2021-05-15 18:05:53 +02:00
|
|
|
return <canvas id={`weather-icon`} width='50' height='50'></canvas>
|
2021-05-14 18:51:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = (state: GlobalState) => {
|
|
|
|
return {
|
|
|
|
theme: state.theme.theme
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(WeatherIcon);
|