<commit_before>import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import styles from '../styles/Main.css';
import classNames from 'classnames';
import { actions } from '../actions';
import { query, showFilter } from '../selectors';
import { createSelector } from 'reselect';

class SearchBox extends React.PureComponent {

  static propTypes = {
    handleOnSubmit: PropTypes.func.isRequired,
    query: PropTypes.string.isRequired,
    showFilter: PropTypes.bool.isRequired,
    setQuery: PropTypes.func.isRequired,
    toggleShowFilter: PropTypes.func.isRequired
  };

  handleOnChange = (event) => {
    event.preventDefault();
    this.props.setQuery(event.currentTarget.value);
  }

  // For some reason the input.onFocus was overriding a.onClick so use the
  // same function and detect the caller
  handleToggleShowFilter = (event) => {
    event.preventDefault();
    const forceOpen = event.currentTarget.name === 'query';
    this.props.toggleShowFilter({ forceOpen: forceOpen });
  }

  render() {
    const { query, showFilter } = this.props;
    return (
      <fieldset className={classNames(styles.SearchBox, 'form-inline SearchBox')}>
        <div className={classNames(styles.searchBox, 'form-group')}>
          <label className={classNames(styles.searchLabel, 'input-group')}>
            <a className={classNames(styles.ShowFilter, styles.Fish, 'input-group-addon btn btn-primary ShowFilter')}
              onClick={this.handleToggleShowFilter}
            >
              Browse <span>{showFilter ? '▼' : '◄' }</span>
            </a>
            <input name="query"
                value={query}
                onChange={this.handleOnChange}
                onClick={this.handleToggleShowFilter}
                className={classNames('form-control')}
                placeholder="Find plugins..."
            />
            <input type="submit" className="sr-only" />
            <div className={classNames(styles.SearchBtn, 'input-group-addon SearchBtn btn btn-primary')}
                onClick={this.props.handleOnSubmit}>
              <i className={classNames('icon-search')} />
            </div>
          </label>
        </div>
      </fieldset>
    );
  }

}

const selectors = createSelector(
  [ query, showFilter ],
  ( query, showFilter ) =>
  ({ query, showFilter })
);

export default connect(selectors, actions)(SearchBox);
<commit_msg>[WEBSITE-237] set focus to the searchbox automatically<commit_after>import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import styles from '../styles/Main.css';
import classNames from 'classnames';
import { actions } from '../actions';
import { query, showFilter } from '../selectors';
import { createSelector } from 'reselect';

class SearchBox extends React.PureComponent {

  static propTypes = {
    handleOnSubmit: PropTypes.func.isRequired,
    query: PropTypes.string.isRequired,
    showFilter: PropTypes.bool.isRequired,
    setQuery: PropTypes.func.isRequired,
    toggleShowFilter: PropTypes.func.isRequired
  };

  handleOnChange = (event) => {
    event.preventDefault();
    this.props.setQuery(event.currentTarget.value);
  }

  // For some reason the input.onFocus was overriding a.onClick so use the
  // same function and detect the caller
  handleToggleShowFilter = (event) => {
    event.preventDefault();
    const forceOpen = event.currentTarget.name === 'query';
    this.props.toggleShowFilter({ forceOpen: forceOpen });
  }

  render() {
    const { query, showFilter } = this.props;
    return (
      <fieldset className={classNames(styles.SearchBox, 'form-inline SearchBox')}>
        <div className={classNames(styles.searchBox, 'form-group')}>
          <label className={classNames(styles.searchLabel, 'input-group')}>
            <a className={classNames(styles.ShowFilter, styles.Fish, 'input-group-addon btn btn-primary ShowFilter')}
              onClick={this.handleToggleShowFilter}
            >
              Browse <span>{showFilter ? '▼' : '◄' }</span>
            </a>
            <input name="query"
                value={query}
                autoFocus
                onChange={this.handleOnChange}
                onClick={this.handleToggleShowFilter}
                className={classNames('form-control')}
                placeholder="Find plugins..."
            />
            <input type="submit" className="sr-only" />
            <div className={classNames(styles.SearchBtn, 'input-group-addon SearchBtn btn btn-primary')}
                onClick={this.props.handleOnSubmit}>
              <i className={classNames('icon-search')} />
            </div>
          </label>
        </div>
      </fieldset>
    );
  }

}

const selectors = createSelector(
  [ query, showFilter ],
  ( query, showFilter ) =>
  ({ query, showFilter })
);

export default connect(selectors, actions)(SearchBox);

{'fraction_non_alphanumeric': 0.13173530014341323, 'fraction_numerical': 0.0006146281499692685, 'mean_word_length': 2.758275596612779, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 39, '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': '2460800', 'n_tokens_mistral': 1349, 'n_tokens_neox': 1354, 'n_words': 295}