-
Notifications
You must be signed in to change notification settings - Fork 0
/
layout.js
46 lines (43 loc) · 1.34 KB
/
layout.js
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
const Layout = (props) => {
let weatherImg = "";
let infoList = null;
if (props.state.flag === "forcast") {
infoList = props.state.list.map((item) => {
if (item.weather[0].main === "Clouds") {
weatherImg = <img src="./img/cloud.png" />;
} else if (item.weather[0].main === "Clear") {
weatherImg = <img src="./img/sun.png" />;
} else if (item.weather[0].main === "Rain") {
weatherImg = <img src="./img/rain3.png" />;
}
return (
<div key={item.dt} className="houerly-forcast">
<p className="date">{item.dt_txt}</p>
<p className="temperature">
{(item.main.temp * 1).toFixed(1)}{" "}
{item.main.temp ? <span>°C</span> : null}
</p>
<p className="weather">{item.weather[0].description}</p>
{weatherImg}
</div>
);
});
}
return (
<main>
<h1>{props.state.error ? "Sorry invalid location" : props.state.city}</h1>
{infoList ? (
infoList
) : (
<div className="current">
<p className="temperature">
{props.state.temp}
{props.state.temp ? <span>°C</span> : null}
</p>
<p className="date">{props.state.date}</p>
<p className="weather">{props.state.weather}</p>
</div>
)}
</main>
);
};