From 55ebc9810216b4a0aaa2c4a5e99eeaf55ce68877 Mon Sep 17 00:00:00 2001 From: Monica Powell Date: Thu, 19 Apr 2018 19:55:07 -0400 Subject: [PATCH 1/2] round temperature to nearest whole number --- src/components/Header.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/Header.js b/src/components/Header.js index f2372a5..cda2df2 100644 --- a/src/components/Header.js +++ b/src/components/Header.js @@ -20,6 +20,7 @@ class HeaderContainer extends Component { }); getWeather(latitude, longitude).then((weather) => { + weather = Math.round(weather); this.setState({currentWeather: weather}) }).catch(function(err){ console.log('Error retrieving the current weather: ', err); @@ -72,7 +73,7 @@ class HeaderContainer extends Component { this.props.updateCurrentCity(this.state.currentCity); } } - + componentDidMount() { this.getMyLocation(); } @@ -94,4 +95,4 @@ export default GoogleApiWrapper({ apiKey: (process.env.REACT_APP_GKEY), libraries: ['places'], version: '3' -})(HeaderContainer) \ No newline at end of file +})(HeaderContainer) From 67c5bf8a1d8135195feadda825242713c8ee2157 Mon Sep 17 00:00:00 2001 From: Monica Powell Date: Thu, 19 Apr 2018 19:58:47 -0400 Subject: [PATCH 2/2] round temperature to nearest whole number --- src/components/Header.js | 54 +++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/src/components/Header.js b/src/components/Header.js index cda2df2..3df1cfe 100644 --- a/src/components/Header.js +++ b/src/components/Header.js @@ -2,11 +2,20 @@ import React, { Component } from 'react'; import {getCity} from '../services/geolocation.js'; import {getWeather} from '../services/weather.js'; import {GoogleApiWrapper} from 'google-maps-react'; - +import Image from '../img/24.png'; class HeaderContainer extends Component { - state = { - }; + state = {}; + + componentDidMount() { + this.getMyLocation(); + } + + componentWillUpdate(prevProps, prevState) { + if (prevState.currentCity !== this.state.currentCity) { + this.props.setCurrentCity(this.state.currentCity); + } + } getCityWeather(latitude, longitude) { const {setCurrentCity} = this.props; @@ -27,16 +36,18 @@ class HeaderContainer extends Component { }) } - getMyLocation = () => { - const {handleLocationChange} = this.props; + const { + handleLocationChange, + setUserPosition + } = this.props; const pos = { lat: parseFloat(localStorage.getItem('lat')), lng: parseFloat(localStorage.getItem('lng')) } handleLocationChange(pos); - + setUserPosition(pos); // ***Get Location from Cache if (pos.lat && pos.lng) { this.getCityWeather(pos.lat, pos.lng); @@ -49,11 +60,17 @@ class HeaderContainer extends Component { // ***Get Location from getCurrentPosition const currentLocation = (position) => { + const { + handleLocationChange, + setUserPosition + } = this.props + const pos = { lat: position.coords.latitude, lng: position.coords.longitude } - handleLocationChange(pos); + setUserPosition(pos) + handleLocationChange(pos) localStorage.setItem('lat', pos.lat); localStorage.setItem('lng', pos.lng); @@ -68,24 +85,15 @@ class HeaderContainer extends Component { } } - componentWillUpdate(prevProps, prevState) { - if (prevState.currentCity !== this.state.currentCity) { - this.props.updateCurrentCity(this.state.currentCity); - } - } - - componentDidMount() { - this.getMyLocation(); - } - - render () { - const message = (this.state.currentCity && this.state.currentWeather) ? - `Welcome to Mappa. You're in ${this.state.currentCity}. It is currently ${this.state.currentWeather}°F` : - `Welcome to Mappa.`; + const {currentCity, currentWeather} = this.state; + const message = (this.state.currentCity && this.state.currentWeather) + ? ` You're in ${currentCity}. It is currently ${currentWeather}°F` + : ``; + return( -

- {message} +

+ Welcome to Mappa. {message}

); }