Skip to content

Commit

Permalink
forecast uses fetchFiveDayForecast
Browse files Browse the repository at this point in the history
  • Loading branch information
bdhsu committed Jan 13, 2019
1 parent c41a91c commit b5a36ad
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 12 deletions.
42 changes: 34 additions & 8 deletions src/Forecast.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,58 @@ class Forecast extends Component {
super(props);

this.state = {
error: null,
location: null,
weather: null,
loading: true,
}
}
componentDidMount() {
var location = queryString.parse(this.props.location.search);
this.setState(_ => {
return {
location: location,
loading: false,
}
});
api.fetchFiveDayForecast(location["city"])
.then(function(results) {
if(results === null) {
this.setState(_ => {
return {
error: "seems to be an error",
loading: false,
}
})
}

this.setState(_ => {
return {
error: null,
location: location["city"],
weather: results.list["0"],
loading: false,
}
});
}.bind(this));
}
render() {
var error = this.state.error;
var location = this.state.location;
var weather = this.state.weather;
var loading = this.state.loading;

if(loading === true) {
return <div>loading...</div>
}

if(error) {
return (
<div>
<p>{error}</p>
</div>
)
}

return (


<div className="container">
{/* {JSON.stringify(location["city"])} */}
{JSON.stringify(api.fetchCurrentWeather(location["city"]))}
{JSON.stringify(weather)}
</div>
)
}
Expand Down
9 changes: 5 additions & 4 deletions src/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ module.exports = {
return axios.get(link)
.then(function(results) {
// console.log('current weather results: ' + results);
console.log(JSON.stringify(results["data"]["weather"]));
console.log(results.data.weather);
// console.log(JSON.stringify(results["data"]["weather"]));
// console.log(results.data.weather);
return results.data.weather;
});
},
fetchFiveDayForecast: function(location) {
var link = window.encodeURI(baseURL + "forecast?q=" + location + ",us" + params);
return axios.get(link)
.then(function(results) {
console.log('forecast results: ' + results);
console.log(JSON.stringify(results));
// console.log('forecast results: ' + results);
// console.log(JSON.stringify(results));
return results.data;
});
}
}

0 comments on commit b5a36ad

Please sign in to comment.