2022-10-30 16:56:26 +00:00
|
|
|
import { memo } from 'react';
|
|
|
|
|
2022-04-07 09:25:01 +00:00
|
|
|
import {
|
|
|
|
WiDirectionDownLeft,
|
|
|
|
WiDirectionDownRight,
|
|
|
|
WiDirectionDown,
|
|
|
|
WiDirectionLeft,
|
|
|
|
WiDirectionRight,
|
|
|
|
WiDirectionUpLeft,
|
|
|
|
WiDirectionUpRight,
|
2022-04-08 13:48:36 +00:00
|
|
|
WiDirectionUp,
|
2022-04-11 21:57:07 +00:00
|
|
|
} from 'react-icons/wi';
|
2021-04-26 18:10:00 +00:00
|
|
|
|
2022-04-08 13:48:36 +00:00
|
|
|
// 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 }) {
|
2022-04-08 13:48:36 +00:00
|
|
|
// convert the number OpenWeatherMap gives us to the closest direction or something
|
|
|
|
const directions = [
|
2022-04-11 21:57:07 +00:00
|
|
|
'North',
|
|
|
|
'North-West',
|
|
|
|
'West',
|
|
|
|
'South-West',
|
|
|
|
'South',
|
|
|
|
'South-East',
|
|
|
|
'East',
|
|
|
|
'North-East',
|
2022-04-08 13:48:36 +00:00
|
|
|
];
|
|
|
|
const direction =
|
2022-04-11 21:57:07 +00:00
|
|
|
directions[Math.round(((degrees %= 360) < 0 ? degrees + 360 : degrees) / 45) % 8];
|
2021-04-26 18:10:00 +00:00
|
|
|
|
2021-05-08 09:58:17 +00:00
|
|
|
switch (direction) {
|
2022-04-11 21:57:07 +00:00
|
|
|
case 'North':
|
2022-08-25 16:07:35 +00:00
|
|
|
return <WiDirectionUp />;
|
2022-04-11 21:57:07 +00:00
|
|
|
case 'North-West':
|
2022-08-25 16:07:35 +00:00
|
|
|
return <WiDirectionUpLeft />;
|
2022-04-11 21:57:07 +00:00
|
|
|
case 'West':
|
2022-08-25 16:07:35 +00:00
|
|
|
return <WiDirectionLeft />;
|
2022-04-11 21:57:07 +00:00
|
|
|
case 'South-West':
|
2022-08-25 16:07:35 +00:00
|
|
|
return <WiDirectionDownLeft />;
|
2022-04-11 21:57:07 +00:00
|
|
|
case 'South':
|
2022-08-25 16:07:35 +00:00
|
|
|
return <WiDirectionDown />;
|
2022-04-11 21:57:07 +00:00
|
|
|
case 'South-East':
|
2022-08-25 16:07:35 +00:00
|
|
|
return <WiDirectionDownRight />;
|
2022-04-11 21:57:07 +00:00
|
|
|
case 'East':
|
2022-08-25 16:07:35 +00:00
|
|
|
return <WiDirectionRight />;
|
2022-04-11 21:57:07 +00:00
|
|
|
case 'North-East':
|
2022-08-25 16:07:35 +00:00
|
|
|
return <WiDirectionUpRight />;
|
2022-04-08 13:48:36 +00:00
|
|
|
default:
|
2022-08-25 16:07:35 +00:00
|
|
|
return null;
|
2021-04-26 18:10:00 +00:00
|
|
|
}
|
2022-04-08 13:48:36 +00:00
|
|
|
}
|
2022-10-30 16:56:26 +00:00
|
|
|
|
2022-11-06 11:59:59 +00:00
|
|
|
export default memo(WindDirectionIcon);
|