mue/src/components/widgets/weather/WindDirectionIcon.jsx

53 lines
1.2 KiB
React
Raw Normal View History

2022-10-30 16:56:26 +00:00
import { memo } from 'react';
import {
WiDirectionDownLeft,
WiDirectionDownRight,
WiDirectionDown,
WiDirectionLeft,
WiDirectionRight,
WiDirectionUpLeft,
WiDirectionUpRight,
WiDirectionUp,
} from 'react-icons/wi';
// degrees are imported because of a potential bug, IDK what causes it, but now it is fixed
2022-10-30 16:56:26 +00:00
function WindDirectionIcon({ degrees }) {
// convert the number OpenWeatherMap gives us to the closest direction or something
const directions = [
'North',
'North-West',
'West',
'South-West',
'South',
'South-East',
'East',
'North-East',
];
const direction =
directions[Math.round(((degrees %= 360) < 0 ? degrees + 360 : degrees) / 45) % 8];
switch (direction) {
case 'North':
2022-08-25 16:07:35 +00:00
return <WiDirectionUp />;
case 'North-West':
2022-08-25 16:07:35 +00:00
return <WiDirectionUpLeft />;
case 'West':
2022-08-25 16:07:35 +00:00
return <WiDirectionLeft />;
case 'South-West':
2022-08-25 16:07:35 +00:00
return <WiDirectionDownLeft />;
case 'South':
2022-08-25 16:07:35 +00:00
return <WiDirectionDown />;
case 'South-East':
2022-08-25 16:07:35 +00:00
return <WiDirectionDownRight />;
case 'East':
2022-08-25 16:07:35 +00:00
return <WiDirectionRight />;
case 'North-East':
2022-08-25 16:07:35 +00:00
return <WiDirectionUpRight />;
default:
2022-08-25 16:07:35 +00:00
return null;
}
}
2022-10-30 16:56:26 +00:00
2022-11-06 11:59:59 +00:00
export default memo(WindDirectionIcon);