<commit_before>
var ReactWeather = React.createClass({
  getInitialState: function() {
    return {
      citiesArr: [],
      currentCity: ''
    };
  },

  componentDidMount: function() {
    this._getGeoOfUser();
    this._getCitysFromStorage();
    //this._updateWeatherState('London');
  },

  componentDidUpdate: function() {
    this._setCitysToStorage();
  },

  _getCitysFromStorage: function() {
    //localStorage.removeItem('citiesArr');
    if(typeof localStorage['citiesArr'] === 'undefined') {
      localStorage['citiesArr'] = '[]';
    }

    this.setState({
      citiesArr: JSON.parse(localStorage['citiesArr'])
    });
  },

  _setCitysToStorage: function() {
    localStorage['citiesArr'] = JSON.stringify(this.state.citiesArr);
  },

  _getGeoOfUser: function() {
    var self = this;

    if (!navigator.geolocation) {
      this.state.currentCity = 'Can\'t get geo!';
      return;
    }

    function success(position) {
      var pos = {
        lat: position.coords.latitude,
        lon: position.coords.longitude
      };
      console.log('Geo success: %o', pos);

      self._updateWeatherState(pos);
    };

    function error() {
      console.log('Geo FAIL!');
    };

    navigator.geolocation.getCurrentPosition(success, error);
  },

  _updateWeatherState: function(arg) {

    var self = this;
    var appID = '2de143494c0b295cca9337e1e96b00e0';
    var url = 'http://api.openweathermap.org/data/2.5/weather';

    var query = (typeof arg === 'object') ? 
      {lat: arg.lat, lon: arg.lon} : {q: arg};

    query.appid = appID;

    console.log(query);

    $.get(url, query, function(data) {
      if ( self.isMounted() ) {
        self.setState({
          currentCity: 'test', //arg,
          temp: data.main.temp,
          icon: data.weather[0].icon,
          pressure: data.main.pressure,
          humidity: data.main.humidity
        });
      }
    });
  },

  _addCity: function(city) {
    if(city === '') {
      return
    }

    this.setState(function(state) {
      var temp = state.citiesArr;
      temp.push(city);
      state.citiesArr = temp;
    });
  },

  _getCitiesLine: function() {
    var self = this;
    return self.state.citiesArr.map(function(value, key) {
      var className = (value === self.state.currentCity) ? 'selectCity' : 'cityNames';
      return ( <span className={className} key={key} onClick={self.cityClickHandler}>{value}</span> )
    });<commit_msg>F: problem with state.currentCity in  _updateWeatherState<commit_after>
var ReactWeather = React.createClass({
  getInitialState: function() {
    return {
      citiesArr: [],
      currentCity: ''
    };
  },

  componentDidMount: function() {
    this._getGeoOfUser();
    this._getCitysFromStorage();
    //this._updateWeatherState('London');
  },

  componentDidUpdate: function() {
    this._setCitysToStorage();
  },

  _getCitysFromStorage: function() {
    //localStorage.removeItem('citiesArr');
    if(typeof localStorage['citiesArr'] === 'undefined') {
      localStorage['citiesArr'] = '[]';
    }

    this.setState({
      citiesArr: JSON.parse(localStorage['citiesArr'])
    });
  },

  _setCitysToStorage: function() {
    localStorage['citiesArr'] = JSON.stringify(this.state.citiesArr);
  },

  _getGeoOfUser: function() {
    var self = this;

    if (!navigator.geolocation) {
      this.state.currentCity = 'Can\'t get geo!';
      return;
    }

    function success(position) {
      var pos = {
        lat: position.coords.latitude,
        lon: position.coords.longitude
      };
      console.log('Geo success: %o', pos);

      self._updateWeatherState(pos);
    };

    function error() {
      console.log('Geo FAIL!');
    };

    navigator.geolocation.getCurrentPosition(success, error);
  },

  _updateWeatherState: function(arg) {

    var self = this;
    var appID = '2de143494c0b295cca9337e1e96b00e0';
    var url = 'http://api.openweathermap.org/data/2.5/weather';

    var city = '';
    var query = {};
    if (typeof arg === 'object') {
      query.lat = arg.lat;
      query.lon = arg.lon;
      city = 'You Geolocation Weather!';
    } else {
      query.q = arg;
      city = arg;
    }
    query.appid = appID;

    console.log(query);

    $.get(url, query, function(data) {
      if ( self.isMounted() ) {
        self.setState({
          currentCity: city,
          temp: data.main.temp,
          icon: data.weather[0].icon,
          pressure: data.main.pressure,
          humidity: data.main.humidity
        });
      }
    });
  },

  _addCity: function(city) {
    if(city === '') {
      return
    }

    this.setState(function(state) {
      var temp = state.citiesArr;
      temp.push(city);
      state.citiesArr = temp;
    });
  },

  _getCitiesLine: function() {
    var self = this;
    return self.state.citiesArr.map(function(value, key) {
      var className = (value === self.state.currentCity) ? 'selectCity' : 'cityNames';
      return ( <span className={className} key={key} onClick={self.cityClickHandler}>{value}</span> )
    });
{'fraction_non_alphanumeric': 0.15294584407855585, 'fraction_numerical': 0.009521920253917874, 'mean_word_length': 2.6065808297567954, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '160808', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1643, 'n_words': 282}