2021-05-14 18:51:56 +02:00
|
|
|
import { useEffect } from 'react';
|
2021-11-09 13:46:07 +01:00
|
|
|
import { useSelector } from 'react-redux';
|
2021-05-15 18:05:53 +02:00
|
|
|
import { Skycons } from 'skycons-ts';
|
2021-11-09 13:46:07 +01:00
|
|
|
import { State } from '../../../../store/reducers';
|
2021-05-15 18:05:53 +02:00
|
|
|
import { IconMapping, TimeOfDay } from './IconMapping';
|
2021-05-14 18:51:56 +02:00
|
|
|
|
2021-11-09 13:46:07 +01:00
|
|
|
interface Props {
|
2021-05-15 18:05:53 +02:00
|
|
|
weatherStatusCode: number;
|
2021-05-21 18:55:21 +02:00
|
|
|
isDay: number;
|
2021-05-14 18:51:56 +02:00
|
|
|
}
|
|
|
|
|
2021-11-09 13:46:07 +01:00
|
|
|
export const WeatherIcon = (props: Props): JSX.Element => {
|
2022-03-24 14:56:36 +01:00
|
|
|
const { activeTheme } = useSelector((state: State) => state.theme);
|
2021-11-09 13:46:07 +01:00
|
|
|
|
2021-05-21 18:55:21 +02:00
|
|
|
const icon = props.isDay
|
2021-06-10 13:05:55 +02:00
|
|
|
? new IconMapping().mapIcon(props.weatherStatusCode, TimeOfDay.day)
|
|
|
|
: new IconMapping().mapIcon(props.weatherStatusCode, TimeOfDay.night);
|
2021-05-15 18:05:53 +02:00
|
|
|
|
2021-05-14 18:51:56 +02:00
|
|
|
useEffect(() => {
|
|
|
|
const delay = setTimeout(() => {
|
2022-03-24 14:56:36 +01:00
|
|
|
const skycons = new Skycons({ color: activeTheme.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-11-09 13:46:07 +01:00
|
|
|
};
|
2022-03-24 14:56:36 +01:00
|
|
|
}, [props.weatherStatusCode, icon, activeTheme.colors.accent]);
|
2021-05-14 18:51:56 +02:00
|
|
|
|
2021-11-09 13:46:07 +01:00
|
|
|
return <canvas id={`weather-icon`} width="50" height="50"></canvas>;
|
|
|
|
};
|