<commit_before>/* eslint max-lines: 0 */
import React, { Component } from "react";
import PropTypes from 'prop-types';
import {
	TYPES,
	AppbaseSensorHelper as helper,
	AppbaseChannelManager as manager
} from "@appbaseio/reactivebase";
import classNames from "classnames";
import axios from "axios";
import Slider from "rc-slider";
import Select from "react-select";

import _ from "lodash";

export default class GeoDistanceSlider extends Component {
	constructor(props) {
		super(props);
		this.urlParams = props.URLParams ? helper.URLParams.get(props.componentId, false, true) : null;
		this.defaultSelected = this.urlParams !== null ? this.urlParams : this.props.defaultSelected;
		let value = this.defaultSelected && this.defaultSelected.distance ?
			this.defaultSelected.distance < this.props.range.start ?
			this.props.range.start : this.defaultSelected.distance : this.props.range.start;
		value = parseInt(value, 10);
		if (this.defaultSelected) {
			this.defaultSelected.distance = parseInt(this.defaultSelected.distance, 10);
		}
		this.state = {
			currentValue: null,
			currentDistance: value + this.props.unit,
			userLocation: null,
			value
		};
		this.type = "geo_distance";
		this.locString = "";
		this.result = {
			options: []
		};
		this.sortInfo = {
			type: "_geo_distance",
			order: "asc",
			unit: "mi"
		};
		this.handleChange = this.handleChange.bind(this);
		this.loadOptions = this.loadOptions.bind(this);
		this.customQuery = this.customQuery.bind(this);
		this.getUserLocation = this.getUserLocation.bind(this);
		this.setDefaultLocation = this.setDefaultLocation.bind(this);
		this.handleValuesChange = this.handleValuesChange.bind(this);
		this.handleResults = this.handleResults.bind(this);
		this.unitFormatter = this.unitFormatter.bind(this);
	}

	// Set query information
	componentWillMount() {
		this.previousQuery = null;	// initial value for onQueryChange
		this.googleMaps = window.google.maps;
		this.getUserLocation();
		this.setQueryInfo();
		this.checkDefault();
		this.listenFilter();
	}

	componentWillUpdate() {
		if(!_.isEqual(this.defaultSelected, this.defaultSelected)) {
			this.defaultSelected = this.defaultSelected;
			this.checkDefault();
		}
	}

	componentWillUnmount() {
		if(this.filterListener) {
			this.filterListener.remove();
		}
	}

	listenFilter() {
		this.filterListener = helper.sensorEmitter.addListener("clearFilter", (data) => {
			if(data === this.props.componentId) {
				this.defaultValue = null;
				this.changeValue(this.defaultValue);
			}
		});
	}

	checkDefault() {
		this.urlParams = this.props.URLParams ? helper.URLParams.get(this.props.componentId, false, true) : null;
		const defaultValue = this.urlParams !== null ? this.urlParams : this.props.defaultSelected;
		this.changeValue(defaultValue);
	}

	changeValue(defaultValue) {
		if(defaultValue && defaultValue.location) {
			let currentValue = defaultValue.location;
			this.result.options.push({
				value: currentValue,
				label: currentValue
			});
			this.setState({
				currentValue: {
					value: currentValue,
					label: currentValue
				}
			}, this.getCoordinates(currentValue.value, this.handleResults));
		}
		else if(defaultValue && defaultValue.distance) {
			this.getUserLocation(this.setDefaultLocation);
			this.handleResults(defaultValue.distance);
		}
		else if(defaultValue === null) {
			this.setState({
				currentDistance: null,
				currentValue: null
			}, this.executeQuery)<commit_msg>minor fixes<commit_after>/* eslint max-lines: 0 */
import React, { Component } from "react";
import PropTypes from 'prop-types';
import {
	TYPES,
	AppbaseSensorHelper as helper,
	AppbaseChannelManager as manager
} from "@appbaseio/reactivebase";
import classNames from "classnames";
import axios from "axios";
import Slider from "rc-slider";
import Select from "react-select";

import _ from "lodash";

export default class GeoDistanceSlider extends Component {
	constructor(props) {
		super(props);
		this.urlParams = props.URLParams ? helper.URLParams.get(props.componentId, false, true) : null;
		this.defaultSelected = this.urlParams !== null ? this.urlParams : this.props.defaultSelected;
		let value = this.defaultSelected && this.defaultSelected.distance ?
			this.defaultSelected.distance < this.props.range.start ?
			this.props.range.start : this.defaultSelected.distance : this.props.range.start;
		value = parseInt(value, 10);
		if (this.defaultSelected) {
			this.defaultSelected.distance = parseInt(this.defaultSelected.distance, 10);
		}
		this.state = {
			currentValue: null,
			currentDistance: value + this.props.unit,
			userLocation: null,
			value
		};
		this.type = "geo_distance";
		this.locString = "";
		this.result = {
			options: []
		};
		this.sortInfo = {
			type: "_geo_distance",
			order: "asc",
			unit: "mi"
		};
		this.handleChange = this.handleChange.bind(this);
		this.loadOptions = this.loadOptions.bind(this);
		this.customQuery = this.customQuery.bind(this);
		this.getUserLocation = this.getUserLocation.bind(this);
		this.setDefaultLocation = this.setDefaultLocation.bind(this);
		this.handleValuesChange = this.handleValuesChange.bind(this);
		this.handleResults = this.handleResults.bind(this);
		this.unitFormatter = this.unitFormatter.bind(this);
	}

	// Set query information
	componentWillMount() {
		this.previousQuery = null;	// initial value for onQueryChange
		this.googleMaps = window.google.maps;
		this.getUserLocation();
		this.setQueryInfo();
		this.checkDefault();
		this.listenFilter();
	}

	componentWillUpdate() {
		if(!_.isEqual(this.defaultSelected, this.defaultSelected)) {
			this.defaultSelected = this.defaultSelected;
			this.checkDefault();
		}
	}

	componentWillUnmount() {
		if(this.filterListener) {
			this.filterListener.remove();
		}
	}

	listenFilter() {
		this.filterListener = helper.sensorEmitter.addListener("clearFilter", (data) => {
			if(data === this.props.componentId) {
				this.defaultValue = null;
				this.changeValue(this.defaultValue);
			}
		});
	}

	checkDefault() {
		this.urlParams = this.props.URLParams ? helper.URLParams.get(this.props.componentId, false, true) : null;
		const defaultValue = this.urlParams !== null ? this.urlParams : this.props.defaultSelected;
		this.changeValue(defaultValue);
	}

	changeValue(defaultValue) {
		if(defaultValue && defaultValue.location) {
			let currentValue = defaultValue.location;
			this.result.options.push({
				value: currentValue,
				label: currentValue
			});
			this.setState({
				currentValue: {
					value: currentValue,
					label: currentValue
				}
			}, this.getCoordinates(currentValue, this.handleResults));
		}
		else if(defaultValue && defaultValue.distance) {
			this.getUserLocation(this.setDefaultLocation);
			this.handleResults(defaultValue.distance);
		}
		else if(defaultValue === null) {
			this.setState({
				currentDistance: null,
				currentValue: null
			}, this.executeQuery)
{'fraction_non_alphanumeric': 0.1278968713789108, 'fraction_numerical': 0.0014484356894553883, 'mean_word_length': 4.332046332046332, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6865320', 'n_tokens_mistral': 2380, 'n_tokens_neox': 2116, 'n_words': 392}