Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. import React, { Component } from 'react'
  2. import { getWeatherClass } from './WeatherClass'
  3.  
  4. class WeatherDisplay extends Component{
  5. constructor(props){
  6. super(props)
  7.  
  8. this.state ={
  9. country:''
  10. }
  11. this.changeIntoCelsius = this.changeIntoCelsius.bind(this)
  12. this.changeIntoFahrenheit = this.changeIntoFahrenheit.bind(this)
  13. }
  14.  
  15. changeIntoCelsius(event){
  16. event.preventDefault()
  17. const { temperature } = this.props
  18. const temp_celsius = (temperature-273.15).toFixed(1)
  19. document.querySelector('.wi-celsius').style.opacity= "1"
  20. document.querySelector('.wi-fahrenheit').style.opacity= "0.4"
  21. document.querySelector('.temp').innerHTML = `${temp_celsius}°`
  22. }
  23.  
  24. changeIntoFahrenheit(event){
  25. event.preventDefault()
  26. const { temperature } = this.props
  27. const temp_fahrenheit = ((9/5)*(temperature-273.15)+32).toFixed(1)
  28. event.preventDefault()
  29. document.querySelector('.wi-fahrenheit').style.opacity= "1"
  30. document.querySelector('.wi-celsius').style.opacity= "0.4"
  31. document.querySelector('.temp').innerHTML = `${temp_fahrenheit}°`
  32. }
  33.  
  34.  
  35. render(){
  36. const {id, city, country, country_name, description, temperature, humidity, speed} = this.props
  37. const temp = (temperature-273.15).toFixed(1)
  38. const months = [ "January", "February", "March", "April", "May", "June",
  39. "July", "August", "September", "October", "November", "December" ];
  40. const days = ["Sunday","Monday","Tueday","Wednesday","Thursday","Friday","Saturday"]
  41.  
  42. return(
  43. <div className="weather-box">
  44. <div className="user-location">
  45. <h2 className="place">{city},<br/>{country_name || country}</h2>
  46. <h3 className="date"><span>{new Date().getDate()}</span> <span>{months[new Date().getMonth()]}</span><br/><span>{days[new Date().getDay()]}</span></h3>
  47. </div>
  48. <hr/>
  49. <div className="temperature-display">
  50. <p className="temp">{temp}&deg;</p>
  51. <p className="weather-condition"><i className={getWeatherClass(id)}></i><br/><span>{description}</span></p>
  52. </div>
  53. <hr/>
  54. <div className="temperature-extras">
  55. <p className="humidity"><i className="wi wi-humidity"></i>&nbsp;<span>{humidity}%</span></p>
  56. <p className="wind_speed"><i className="wi wi-wind-direction"></i>&nbsp;<span>{speed}mph</span></p>
  57. <p className="change_metric"><i className="wi wi-celsius" onClick={this.changeIntoCelsius}></i>&nbsp;
  58. &nbsp;<i className="wi wi-fahrenheit" style={{opacity : 0.4}} onClick={this.changeIntoFahrenheit}></i></p>
  59. </div>
  60. </div>
  61. )
  62. }
  63. }
  64.  
  65. export default WeatherDisplay
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement