Initial commit React Weather App

This commit is contained in:
2017-01-13 16:16:04 -08:00
commit 94757c1d78
14 changed files with 268 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
var React = require('react');
var WeatherForm = require('WeatherForm');
var WeatherMessage = require('WeatherMessage');
var openWeatherMap = require('openWeatherMap');
var Weather = React.createClass({
getInitialState: function () {
return {
isLoading: false
}
},
handleSearch: function (location) {
var that = this;
this.setState({isLoading: true});
openWeatherMap.getTemp(location).then(function (temp) {
that.setState({
location: location,
temp: temp,
isLoading: false
});
}, function (errorMessage) {
that.setState({isLoading: false});
alert(errorMessage);
});
},
render: function () {
var {isLoading, temp, location} = this.state;
function renderMessage () {
if (isLoading) {
return <h3>Fetching weather...</h3>;
} else if (temp && location) {
return <WeatherMessage temp={temp} location={location}/>;
}
}
return (
<div>
<h3>Weather Component</h3>
<WeatherForm onSearch={this.handleSearch}/>
{renderMessage()}
</div>
)
}
});
module.exports = Weather;