<commit_before>var dispatcher = require("./dispatcher.js");
var cachedFetch = require("./cachedfetch.js");
var getUrlParameters = require('./parseurl.js').getUrlParameters;
var getLeadersKey = require("./leaderskey.js");

var LeaderMap = require("./leadermap.react.js");
var LeaderTable = require("./leadertable.react.js");
var LeaderProfile = require("./leaderprofile.react.js");

var Leaderboard = React.createClass({
  getInitialState: function () {
    return {
      selection: {
        iso2: null,
        offset: null,
        profile: null,
        highlight: null
      }
    };
  },

  isMobile: function () {
    return window.matchMedia("only screen and (max-width: 480px)").matches;
  },

  render: function() {
    var map;
    var content;

    if (!this.isMobile()) {
      map = <LeaderMap
        countriesGeoUrl={this.props.config.countriesGeoUrl}
        leafletJSUrl={this.props.config.leafletJSUrl}
        leafletCSSUrl={this.props.config.leafletCSSUrl}
        selection={this.state.selection}
      />;
    }

    if (this.state.selection.profile != null) {
      content = <LeaderProfile
        selection={this.state.selection}
      />;
    } else {
      content = <LeaderTable
        selection={this.state.selection}
      />;
    }

    return (
      <div id="leaderboard" className="section">
        <div className="col span_8_of_12">
          {map}
        </div>
        <div className="col span_4_of_12">
          {content}
        </div>
      </div>
    );
  },

  updateWindowLocation: function (selection) {
    var newLocationParams = [];

    for (var paramName in selection) {
      var paramValue = selection[paramName];
      if (paramValue != null && paramValue.length > 0) {
        newLocationParams.push(paramName + '=' + paramValue);
      }
    }

    var newLocation = "?";
    if (newLocationParams.length > 0) {
      newLocation += newLocationParams.join("&");
    }

    window.history.pushState({}, "", newLocation);
  },

  getLeadersUrl: function (selection) {
    var leadersUrl = this.props.config.globalLeadersUrl;

    if (selection.iso2 != null && selection.iso2.length > 0) {
      leadersUrl = this.props.config.countryLeadersUrl.replace("XX", selection.iso2);
    }

    if (selection.offset != null) {
      leadersUrl += "?offset=" + selection.offset;
    }

    return leadersUrl;
  },

  loadLeadersData: function (selection) {
    var leadersUrl = this.getLeadersUrl(selection);
    return cachedFetch.set(getLeadersKey(selection), leadersUrl);<commit_msg>Additional fix for #165<commit_after>var dispatcher = require("./dispatcher.js");
var cachedFetch = require("./cachedfetch.js");
var getUrlParameters = require('./parseurl.js').getUrlParameters;
var getLeadersKey = require("./leaderskey.js");

var LeaderMap = require("./leadermap.react.js");
var LeaderTable = require("./leadertable.react.js");
var LeaderProfile = require("./leaderprofile.react.js");

var Leaderboard = React.createClass({
  getInitialState: function () {
    return {
      selection: {
        iso2: null,
        offset: null,
        profile: null,
        highlight: null
      }
    };
  },

  isMobile: function () {
    return window.matchMedia("only screen and (max-width: 480px)").matches;
  },

  render: function() {
    var map;
    var content;

    if (!this.isMobile()) {
      map = <LeaderMap
        countriesGeoUrl={this.props.config.countriesGeoUrl}
        leafletJSUrl={this.props.config.leafletJSUrl}
        leafletCSSUrl={this.props.config.leafletCSSUrl}
        selection={this.state.selection}
      />;
    }

    if (this.state.selection.profile != null) {
      content = <LeaderProfile
        selection={this.state.selection}
      />;
    } else {
      content = <LeaderTable
        selection={this.state.selection}
      />;
    }

    return (
      <div id="leaderboard" className="section">
        <div className="col span_8_of_12">
          {map}
        </div>
        <div className="col span_4_of_12">
          {content}
        </div>
      </div>
    );
  },

  updateWindowLocation: function (selection) {
    var newLocationParams = [];

    for (var paramName in selection) {
      var paramValue = selection[paramName];
      if ((paramValue != null) && ((("" + paramValue).length) > 0)) {
        newLocationParams.push(paramName + '=' + paramValue);
      }
    }

    var newLocation = "?";
    if (newLocationParams.length > 0) {
      newLocation += newLocationParams.join("&");
    }

    window.history.pushState({}, "", newLocation);
  },

  getLeadersUrl: function (selection) {
    var leadersUrl = this.props.config.globalLeadersUrl;

    if (selection.iso2 != null && selection.iso2.length > 0) {
      leadersUrl = this.props.config.countryLeadersUrl.replace("XX", selection.iso2);
    }

    if (selection.offset != null) {
      leadersUrl += "?offset=" + selection.offset;
    }

    return leadersUrl;
  },

  loadLeadersData: function (selection) {
    var leadersUrl = this.getLeadersUrl(selection);
    return cachedFetch.set(getLeadersKey(selection), leadersUrl);
{'fraction_non_alphanumeric': 0.1418746315582629, 'fraction_numerical': 0.0068775790921595595, 'mean_word_length': 2.77037037037037, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, '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': '6333737', 'n_tokens_mistral': 1586, 'n_tokens_neox': 1534, 'n_words': 288}