<commit_before>'use strict'
const _ = require('lodash')
const React = require('react')
const { Link } = require('react-router')
const BusyIndicator = require('../busyIndicator.jsx')
const ScrollCaboose = require('../scrollCaboose.jsx')
const ErrorMessage = require('../errorMessage.jsx')
const { connect } = require('react-redux')
const { search: searchUsers } = require('../../flux/users/actions')
const Helmet = require('react-helmet')

const ua = navigator.userAgent
// Are we redirecting after input or waiting until the user manually clicks "apply"?
// Borrowed from rackt/history/modules/DOMUtils.supportsHistory
const useManualApply =
  (
    (ua.indexOf('Android 2.') !== -1 || ua.indexOf('Android 4.0') !== -1) &&
    ua.indexOf('Mobile Safari') !== -1 && ua.indexOf('Chrome') === -1 && ua.indexOf('Windows Phone') === -1
  ) ||
  (ua.indexOf('CriOS') !== -1) ||
  !window.history ||
  !window.history.pushState

class UserSearch extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      error: null,
      queryUpdateTimeout: null,
      workingQuery: this.props.location.query,
      results: [],
      endReached: false,
      scrolledToBottom: false
    }
    this._updateWorkingQuery = this._updateWorkingQuery.bind(this)
    this._correctUrlQuery = this._correctUrlQuery.bind(this)
    this._doSearch = this._doSearch.bind(this)
    this._loadMoreResults = this._loadMoreResults.bind(this)
    this._scrollCabooseListener = this._scrollCabooseListener.bind(this)
    this._onApply = this._onApply.bind(this)
    this._onRevert = this._onRevert.bind(this)
  }
  // Read the search parameters = require(the controls and use them to construct the working query.
  _updateWorkingQuery() {
    // Collect the search parameters = require(the controls.
    let parameters = {
      givenName: this.refs.givenName.value,
      familyName: this.refs.familyName.value,
      emailAddress: this.refs.emailAddress ? this.refs.emailAddress.value : undefined,
      sortBy: this.refs.sortBy.value,
      sortOrder: this.refs.sortOrderDescending.checked ? 'descending' : 'ascending'
    }
    this.setState({workingQuery: parameters})
  }
  // Correct any errors in the provided query.
  _correctUrlQuery(query, options) {
    const { delayed, replace } = options || {}
    let validQuery = {}
    // Only these parameters can be filtered on.
    const validFilter = ['familyName', 'givenName', 'emailAddress']
    for (let i in validFilter) {
      let parameter = validFilter[i]
      if (query[parameter]) {
        validQuery[parameter] = query[parameter]
      }
    }
    // sortBy has valid values and a default.
    const validSortBy = ['familyName', 'givenName', 'emailAddress']
    if (!query.sortBy || (validSortBy.indexOf(query.sortBy) == -1)) {
      validQuery.sortBy = validSortBy[0]
    } else {
      validQuery.sortBy = query.sortBy
    }
    // sortOrder has valid values and a default.
    const validSortOrder = ['ascending', 'descending']
    if (!query.sortOrder || (validSortOrder.indexOf(query.sortOrder) == -1)) {
      validQuery.sortOrder = validSortOrder[0]
    } else {
      validQuery.sortOrder = query.sortOrder
    }
    let navigate = this.props.history[replace
        ? 'replaceState'
        : 'pushState']
    const doRedirect = () => {
      if (!_.isEqual(query, validQuery)) {
        navigate(null, this.props.location.pathname, validQuery)
      }
      if (this.state.queryUpdateTimeout) {
        this.setState({
          queryUpdateTimeout: null
        })
      }
    }
    if (this.state.queryUpdateTimeout) {
      clearTimeout(this.state.queryUpdateTimeout)
    }
    // If the valid query differs from the supplied query, redirect to it.
    if (delayed) {
      // Delay the query update to one second after the most recent edit.
      let queryUpdateTimeout = setTimeout(doRedirect, 500)
      this.setState({
        queryUpdateTimeout: queryUpdateTimeout
      })
    } else {
      doRedirect()
    }
  }
  // Initiate a search.
  _doSearch(newSearch = true) {
    const startingResults = newSearch ? [] : this.state.results
    const endReached = newSearch ? false : this.state.endReached
    this.setState({
      busy: true,
      error: null,
      results: startingResults,
      endReached
    })
    return this._loadMoreResults(startingResults)
      .catch(err => this.setState({<commit_msg>cleanup<commit_after>'use strict'
const _ = require('lodash')
const React = require('react')
const { Link } = require('react-router')
const BusyIndicator = require('../busyIndicator.jsx')
const ScrollCaboose = require('../scrollCaboose.jsx')
const ErrorMessage = require('../errorMessage.jsx')
const { connect } = require('react-redux')
const { search: searchUsers } = require('../../flux/users/actions')
const Helmet = require('react-helmet')

const ua = navigator.userAgent
// Are we redirecting after input or waiting until the user manually clicks "apply"?
// Borrowed from rackt/history/modules/DOMUtils.supportsHistory
const useManualApply =
  (
    (ua.indexOf('Android 2.') !== -1 || ua.indexOf('Android 4.0') !== -1) &&
    ua.indexOf('Mobile Safari') !== -1 && ua.indexOf('Chrome') === -1 && ua.indexOf('Windows Phone') === -1
  ) ||
  (ua.indexOf('CriOS') !== -1) ||
  !window.history ||
  !window.history.pushState

class UserSearch extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      error: null,
      queryUpdateTimeout: null,
      workingQuery: this.props.location.query,
      results: [],
      endReached: false,
      scrolledToBottom: false
    }
    this._updateWorkingQuery = this._updateWorkingQuery.bind(this)
    this._correctUrlQuery = this._correctUrlQuery.bind(this)
    this._doSearch = this._doSearch.bind(this)
    this._loadMoreResults = this._loadMoreResults.bind(this)
    this._scrollCabooseListener = this._scrollCabooseListener.bind(this)
    this._onApply = this._onApply.bind(this)
    this._onRevert = this._onRevert.bind(this)
  }
  // Read the search parameters = require(the controls and use them to construct the working query.
  _updateWorkingQuery() {
    // Collect the search parameters = require(the controls.
    let parameters = {
      givenName: this.refs.givenName.value,
      familyName: this.refs.familyName.value,
      emailAddress: this.refs.emailAddress ? this.refs.emailAddress.value : undefined,
      sortBy: this.refs.sortBy.value,
      sortOrder: this.refs.sortOrderDescending.checked ? 'descending' : 'ascending'
    }
    this.setState({
      workingQuery: parameters
    })
  }
  // Correct any errors in the provided query.
  _correctUrlQuery(query, options) {
    const { delayed, replace } = options || {}
    let validQuery = {}
    // Only these parameters can be filtered on.
    const validFilter = ['familyName', 'givenName', 'emailAddress']
    for (let i in validFilter) {
      let parameter = validFilter[i]
      if (query[parameter]) {
        validQuery[parameter] = query[parameter]
      }
    }
    // sortBy has valid values and a default.
    const validSortBy = ['familyName', 'givenName', 'emailAddress']
    if (!query.sortBy || (validSortBy.indexOf(query.sortBy) == -1)) {
      validQuery.sortBy = validSortBy[0]
    } else {
      validQuery.sortBy = query.sortBy
    }
    // sortOrder has valid values and a default.
    const validSortOrder = ['ascending', 'descending']
    if (!query.sortOrder || (validSortOrder.indexOf(query.sortOrder) == -1)) {
      validQuery.sortOrder = validSortOrder[0]
    } else {
      validQuery.sortOrder = query.sortOrder
    }
    let navigate = this.props.history[replace
        ? 'replaceState'
        : 'pushState']
    const doRedirect = () => {
      if (!_.isEqual(query, validQuery)) {
        navigate(null, this.props.location.pathname, validQuery)
      }
      if (this.state.queryUpdateTimeout) {
        this.setState({
          queryUpdateTimeout: null
        })
      }
    }
    if (this.state.queryUpdateTimeout) {
      clearTimeout(this.state.queryUpdateTimeout)
    }
    // If the valid query differs from the supplied query, redirect to it.
    if (delayed) {
      // Delay the query update to half a second after the most recent edit.
      let queryUpdateTimeout = setTimeout(doRedirect, 500)
      this.setState({
        queryUpdateTimeout: queryUpdateTimeout
      })
    } else {
      doRedirect()
    }
  }
  // Initiate a search.
  _doSearch(newSearch = true) {
    const startingResults = newSearch ? [] : this.state.results
    const endReached = newSearch ? false : this.state.endReached
    this.setState({
      busy: true,
      error: null,
      results: startingResults,
      endReached
    })
    return this._loadMoreResults(startingResults)
      .catch(err => this.setState({
{'fraction_non_alphanumeric': 0.12535547719258333, 'fraction_numerical': 0.0036400864520532363, 'mean_word_length': 3.0779220779220777, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2641500', 'n_tokens_mistral': 2638, 'n_tokens_neox': 2605, 'n_words': 603}