<commit_before>import React from 'react';
import request from 'request'
import { Input } from 'quill-component-library/dist/componentLibrary'
import LoadingIndicator from './loading_indicator.jsx';

const mapSearchSrc = `${process.env.CDN_URL}/images/onboarding/map-search.svg`

class SchoolSelector extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      search: '',
      schools: [],
      errors: {},
      loading: true
    }

    this.updateKeyValue = this.updateKeyValue.bind(this);
    this.update = this.update.bind(this);
    this.search = this.search.bind(this)
    this.enableLocationAccess = this.enableLocationAccess.bind(this)
    this.getLocation = this.getLocation.bind(this)
    this.noLocation = this.noLocation.bind(this)
    this.renderSchoolsList = this.renderSchoolsList.bind(this)
    this.renderSchoolsListSection = this.renderSchoolsListSection.bind(this)
  }

  componentDidMount() {
    this.enableLocationAccess()
  }

  getLocation(position) {
    const { latitude, longitude, } = position.coords
    this.setState({ latitude, longitude, loading: true, }, this.search)
  }

  noLocation() {
    this.setState({ loading: false, })
  }

  enableLocationAccess() {
    navigator.geolocation.getCurrentPosition(this.getLocation, this.noLocation);
  }

  updateKeyValue(key, value) {
    const newState = Object.assign({}, this.state);
    newState[key] = value;
    this.setState(newState, this.search);
  }

  update(e) {
    this.updateKeyValue(e.target.id, e.target.value)
  }

  search() {
    const { search, latitude, longitude } = this.state
    request({
      url: `${process.env.DEFAULT_URL}/schools`,
      qs: { search, lat: latitude, lng: longitude, },
      method: 'GET',
    },
    (err, httpResponse, body) => {
      if (httpResponse.statusCode === 200) {
        const schools = JSON.parse(body).data
        this.setState({ schools, loading: false})
      } else {
        console.log('err', err)
      }
    });
  }<commit_msg>don't perform school search until a full zip code is entered<commit_after>import React from 'react';
import request from 'request'
import { Input } from 'quill-component-library/dist/componentLibrary'
import LoadingIndicator from './loading_indicator.jsx';

const mapSearchSrc = `${process.env.CDN_URL}/images/onboarding/map-search.svg`

class SchoolSelector extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      search: '',
      schools: [],
      errors: {},
      loading: true
    }

    this.updateKeyValue = this.updateKeyValue.bind(this);
    this.update = this.update.bind(this);
    this.search = this.search.bind(this)
    this.enableLocationAccess = this.enableLocationAccess.bind(this)
    this.getLocation = this.getLocation.bind(this)
    this.noLocation = this.noLocation.bind(this)
    this.renderSchoolsList = this.renderSchoolsList.bind(this)
    this.renderSchoolsListSection = this.renderSchoolsListSection.bind(this)
  }

  componentDidMount() {
    this.enableLocationAccess()
  }

  getLocation(position) {
    const { latitude, longitude, } = position.coords
    this.setState({ latitude, longitude, loading: true, }, this.search)
  }

  noLocation() {
    this.setState({ loading: false, })
  }

  enableLocationAccess() {
    navigator.geolocation.getCurrentPosition(this.getLocation, this.noLocation);
  }

  updateKeyValue(key, value) {
    const newState = Object.assign({}, this.state);
    newState[key] = value;
    this.setState(newState, this.search);
  }

  update(e) {
    this.updateKeyValue(e.target.id, e.target.value)
  }

  search() {
    const { search, latitude, longitude } = this.state

    const wholeSearchIsNumbersRegex = /^\d+$/

    // if they're typing a zip code, don't search until the full zip code is entered
    if (search.match(wholeSearchIsNumbersRegex) && search.length < 5) {
      return null
    }

    request({
      url: `${process.env.DEFAULT_URL}/schools`,
      qs: { search, lat: latitude, lng: longitude, },
      method: 'GET',
    },
    (err, httpResponse, body) => {
      if (httpResponse.statusCode === 200) {
        const schools = JSON.parse(body).data
        this.setState({ schools, loading: false})
      } else {
        console.log('err', err)
      }
    });
  }
{'fraction_non_alphanumeric': 0.1326506865254829, 'fraction_numerical': 0.0016290435187340006, 'mean_word_length': 3.3195979899497488, 'pattern_counts': {'":': 0, '<': 4, '<?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': '379793', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1314, 'n_words': 260}