<commit_before>import React, { Component, PropTypes } from 'react';
import Modernizr from 'modernizr';
import '~/assets/stylesheets/Input.scss';
import '~/assets/stylesheets/Utility.scss';
import PokemonSelection from '~/components/PokemonSelection';
import DustSelection from '~/components/DustSelection';
import * as Helper from '~/components/Helper/HelperFunctions';

class Input extends Component {
  static propTypes = {
    onInputSubmitCB: PropTypes.func.isRequired,
  }

  constructor(props) {
    super(props);

    this.state = {
      trainerLevel: '',
      name: '',
      cp: '',
      hp: '',
      dust: '',
      isNewSearch: true,
      wild: true,
      filterSearch: false,
    };
    this.onSubmit = this.onSubmit.bind(this);
    this.onNewSearchSubmit = this.onNewSearchSubmit.bind(this);
    this.onFilterSubmit = this.onFilterSubmit.bind(this);
    this.onReset = this.onReset.bind(this);
    this.onNameChange = this.onNameChange.bind(this);
    this.onCPChange = this.onCPChange.bind(this);
    this.onHPChange = this.onHPChange.bind(this);
    this.onDustChange = this.onDustChange.bind(this);
    this.onWildChange = this.onWildChange.bind(this);
    this.onTrainerChange = this.onTrainerChange.bind(this);

    this.pokemonList = Helper.getPokemonList();
    this.dustList = Helper.getDustList();
  }

  onReset() {
    this.setState({
      name: '',
      cp: '',
      hp: '',
      dust: '',
      wild: true,
    });
  }

  onSubmit(e) {
    e.preventDefault();

    const { trainerLevel, name, cp, hp, dust } = this.state;

    const validTrainerLevel = Helper.validateLevelEntry(trainerLevel);
    const validPokemon = Helper.validatePokemonEntry(name);
    const validCP = Helper.validateNumericEntry(cp);
    const validHP = Helper.validateNumericEntry(hp);
    const validDust = Helper.validateDustEntry(dust);
    const valid = validPokemon && validCP && validDust && validHP && validTrainerLevel;

    this.onNewSearchSubmit(valid);
  }

  onNewSearchSubmit(valid) {
    const { trainerLevel, name, cp, hp, dust, wild } = this.state;

    if (valid) {
      this.props.onInputSubmitCB(Number(trainerLevel), name.toLowerCase(), Number(cp), Number(hp),
        Number(dust), wild, true);

      this.setState({
        isNewSearch: false,
      });
    }
  }

  onFilterSubmit(valid) {
    const { trainerLevel, name, cp, hp, dust } = this.state;

    if (valid) {
      this.props.onInputSubmitCB(Number(trainerLevel), name.toLowerCase(), Number(cp), Number(hp),
        Number(dust), false, false);
    }
  }

  onNameChange(e) {
    this.setState({
      name: e.target.value,
    });
  }

  onCPChange(e) {
    this.setState({
      cp: e.target.value,
    });
  }

  onHPChange(e) {
    this.setState({
      hp: e.target.value,
    });
  }

  onDustChange(e) {
    this.setState({
      dust: e.target.value,
    });
  }

  onWildChange(e) {
    this.setState({
      wild: e.target.checked,
    });
  }

  onTrainerChange(e) {
    this.setState({
      trainerLevel: e.target.value,
    });
  }

  render() {
    const { trainerLevel, name, cp, hp, dust, isNewSearch } = this.state;
    const { pokemonList, dustList } = this;

    const validTrainerLevel = Helper.validateLevelEntry(trainerLevel);
    const validPokemon = Helper.validatePokemonEntry(name);
    const validCP = Helper.validateNumericEntry(cp);
    const validHP = Helper.validateNumericEntry(hp);<commit_msg>Add trainer level to localStorage<commit_after>import React, { Component, PropTypes } from 'react';
import Modernizr from 'modernizr';
import '~/assets/stylesheets/Input.scss';
import '~/assets/stylesheets/Utility.scss';
import PokemonSelection from '~/components/PokemonSelection';
import DustSelection from '~/components/DustSelection';
import * as Helper from '~/components/Helper/HelperFunctions';

class Input extends Component {
  static propTypes = {
    onInputSubmitCB: PropTypes.func.isRequired,
  }

  constructor(props) {
    super(props);

    const trainerLevel = localStorage.getItem('trainerLevel') || '';

    this.state = {
      trainerLevel,
      name: '',
      cp: '',
      hp: '',
      dust: '',
      isNewSearch: true,
      wild: true,
      filterSearch: false,
    };
    this.onSubmit = this.onSubmit.bind(this);
    this.onNewSearchSubmit = this.onNewSearchSubmit.bind(this);
    this.onFilterSubmit = this.onFilterSubmit.bind(this);
    this.onReset = this.onReset.bind(this);
    this.onNameChange = this.onNameChange.bind(this);
    this.onCPChange = this.onCPChange.bind(this);
    this.onHPChange = this.onHPChange.bind(this);
    this.onDustChange = this.onDustChange.bind(this);
    this.onWildChange = this.onWildChange.bind(this);
    this.onTrainerChange = this.onTrainerChange.bind(this);

    this.pokemonList = Helper.getPokemonList();
    this.dustList = Helper.getDustList();
  }

  onReset() {
    this.setState({
      name: '',
      cp: '',
      hp: '',
      dust: '',
      wild: true,
    });
  }

  onSubmit(e) {
    e.preventDefault();

    const { trainerLevel, name, cp, hp, dust } = this.state;

    const validTrainerLevel = Helper.validateLevelEntry(trainerLevel);
    const validPokemon = Helper.validatePokemonEntry(name);
    const validCP = Helper.validateNumericEntry(cp);
    const validHP = Helper.validateNumericEntry(hp);
    const validDust = Helper.validateDustEntry(dust);
    const valid = validPokemon && validCP && validDust && validHP && validTrainerLevel;

    this.onNewSearchSubmit(valid);
  }

  onNewSearchSubmit(valid) {
    const { trainerLevel, name, cp, hp, dust, wild } = this.state;

    if (valid) {
      this.props.onInputSubmitCB(Number(trainerLevel), name.toLowerCase(), Number(cp), Number(hp),
        Number(dust), wild, true);

      this.setState({
        isNewSearch: false,
      });
    }
  }

  onFilterSubmit(valid) {
    const { trainerLevel, name, cp, hp, dust } = this.state;

    if (valid) {
      this.props.onInputSubmitCB(Number(trainerLevel), name.toLowerCase(), Number(cp), Number(hp),
        Number(dust), false, false);
    }
  }

  onNameChange(e) {
    this.setState({
      name: e.target.value,
    });
  }

  onCPChange(e) {
    this.setState({
      cp: e.target.value,
    });
  }

  onHPChange(e) {
    this.setState({
      hp: e.target.value,
    });
  }

  onDustChange(e) {
    this.setState({
      dust: e.target.value,
    });
  }

  onWildChange(e) {
    this.setState({
      wild: e.target.checked,
    });
  }

  onTrainerChange(e) {
    localStorage.setItem('trainerLevel', e.target.value);

    this.setState({
      trainerLevel: e.target.value,
    });
  }

  render() {
    const { trainerLevel, name, cp, hp, dust, isNewSearch } = this.state;
    const { pokemonList, dustList } = this;

    const validTrainerLevel = Helper.validateLevelEntry(trainerLevel);
    const validPokemon = Helper.validatePokemonEntry(name);
    const validCP = Helper.validateNumericEntry(cp);
    const validHP = Helper.validateNumericEntry(hp);
{'fraction_non_alphanumeric': 0.13692946058091288, 'fraction_numerical': 0.0, 'mean_word_length': 3.1706443914081146, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6793520', 'n_tokens_mistral': 2350, 'n_tokens_neox': 2302, 'n_words': 408}