SHARE
TWEET

Untitled

a guest Mar 25th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { getWeatherByName, getWeatherForecast } from '../helpers.js';
  2.  
  3. const renderMajorCities = (onCityClick)=> {
  4.     const europeanCapitals = ['London', 'Paris', 'Vienna'];
  5.     const bulgarianCities = ['Varna', 'Plovdiv', 'Sofia'];
  6.  
  7.     europeanCapitals.forEach((city) => {
  8.         renderEuropeanCapital(city, '#european-capitals', onCityClick);
  9.     });
  10.     bulgarianCities.forEach((city) => {
  11.         renderBulgarianCities(city, '#bulgarian-cities', onCityClick);
  12.     });
  13. }
  14.  
  15. const renderEuropeanCapital = (cityName, selector, onCityClick) => {
  16.     getWeatherByName(cityName)
  17.         .then(renderMajorCity.bind(this, selector, onCityClick))
  18. }
  19.  
  20. const renderBulgarianCities = (cityName, selector, onCityClick) => {
  21.     getWeatherByName(cityName)
  22.         .then(renderMajorCity.bind(this, selector, onCityClick))
  23. }
  24.  
  25. const renderMajorCity = (selector, onCityClick, cityData) => {
  26.     const cityName = cityData.location.name;
  27.     const temp = cityData.current.temp_c;
  28.     const icon = cityData.current.condition.text + '<img src="'
  29.     + cityData.current.condition.icon+'"></img>';
  30.     const domElement = $('<div class="city">'+
  31.         '<div> <div class="city-name">'
  32.         + cityName +
  33.         '</div> <div class="temp">'+temp+'°C</div></div>'+'<div class="icon">'+icon+'</div>'+
  34.         '</div>');
  35.     $(selector).append(domElement);
  36.     domElement.click(()=>{
  37.         onCityClick(cityName);
  38.     });
  39. }
  40. export {
  41.     renderMajorCities
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top