diff --git a/src/Forecast.js b/src/Forecast.js
index a42d38a..7e0f376 100644
--- a/src/Forecast.js
+++ b/src/Forecast.js
@@ -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
loading...
}
+
+ if(error) {
+ return (
+
+ )
+ }
+
return (
- {/* {JSON.stringify(location["city"])} */}
- {JSON.stringify(api.fetchCurrentWeather(location["city"]))}
+ {JSON.stringify(weather)}
)
}
diff --git a/src/utils/api.js b/src/utils/api.js
index 7122e9c..6fb3275 100644
--- a/src/utils/api.js
+++ b/src/utils/api.js
@@ -10,8 +10,8 @@ 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;
});
},
@@ -19,8 +19,9 @@ module.exports = {
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;
});
}
}