-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeatherRecord.js
77 lines (73 loc) · 2.44 KB
/
WeatherRecord.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import QueryWeatherData from './QueryWeatherData.js'
import React, { Component } from 'react'
export default class WeatherRecord extends Component {
constructor(props){
super(props)
this.state = {
weatherData: {}
}
this.buttonRef = React.createRef()
}
componentDidMount() {
QueryWeatherData(this, this.props.city)
}
render() {
const {weatherData} = this.state
var textStyle
var imgStyle
if (weatherData.weather){
var textColor = '#5d656e'
/*switch (weatherData.weather[0].main) {
case 'Rain':
textColor = '#6F80B6'
break
case 'Clear':
textColor = '#D2691E'
break
case 'Clouds':
textColor = '#2F4F4F'
break
case 'Drizzle':
textColor = '#008B8B'
break
case 'Thunderstorm':
textColor = '#B16FB6 '
break
case 'Snow':
textColor = '#5B9E9E'
break
default:
textColor = '#696969'
}*/
textStyle = {
color: textColor
}
var imgColor
if (weatherData.weather[0].icon[2] === 'n') {
imgColor = '#8e969f'
} else {
imgColor = '#b1d6ff'
}
imgStyle = {
background: imgColor,
borderRadius: '6px'
}
}
return (
<>
{weatherData.weather ?
<tr style={textStyle} className='align-middle'>
<td><b>{this.props.city}</b></td>
<td>
<img style={imgStyle} width='30'
src={`http://openweathermap.org/img/wn/${weatherData.weather[0].icon}@2x.png`} alt={weatherData.weather[0].description}/>
{' ' + weatherData.weather[0].description}
</td>
<td>{weatherData.main.temp}°C</td>
<td>{weatherData.main.humidity}%</td>
</tr> : null
}
</>
)
}
}