-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForecast.jsx
54 lines (46 loc) · 1.38 KB
/
Forecast.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import React from 'react';
import WeatherDateTime from './WeatherDateTime';
const Forecast = ({ title, forecastData, timezone }) => {
// Control the length of forecast items
const SIZE = 5;
return (
<div className='my-3 text-start'>
{/* Section title */}
<h3 className='text-lg font-medium uppercase'>{`${title} Forecast`}</h3>
<hr className='my-2 ' />
{/* Forecast data */}
<ul className='flex flex-wrap items-center justify-between'>
{forecastData
.filter((_, index) => index < SIZE)
.map((data, index) => {
const forecastTemp =
data.temp instanceof Object ? data.temp.day : data.temp;
const timestamp = data.dt;
const format = title === 'daily' ? 'ccc' : 'hh:mm a';
return (
<li
key={index + 1}
className='flex flex-col items-center justify-start p-3 font-light'
>
{/* Weather Date and Time */}
<WeatherDateTime
timestamp={timestamp}
timezone={timezone}
format={format}
/>
{/* Weather Image */}
<img
src={`https://openweathermap.org/img/wn/${data.weather[0].icon}@2x.png`}
alt='Weather Icon'
className='w-14'
/>
{/* Weather Temperature */}
<p className='font-medium'>{Math.round(forecastTemp)}°</p>
</li>
);
})}
</ul>
</div>
);
};
export default Forecast;