<commit_before>import React from 'react';
import {
  FlatList,
  Text,
  View,
  ActivityIndicator,
  Animated,
  RefreshControl,
  Alert,
} from 'react-native';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { NavigationActions } from 'react-navigation';
import { SearchBar, ListItem } from 'react-native-elements';
import moment from 'moment';

import {
  searchUpdateQuery,
  searchUpdatePastQueries,
} from '../../actions/search';
import { insertPastQuery, getPastQueries } from '../../data/db/dbHelper';
import { styles } from './styles';

class SearchStartScreen extends React.Component {
  componentDidMount() {
    const pastQueries = getPastQueries();
    this.props.updatePastQueries(pastQueries);
  }

  _onSubmit = queryText => {
    this.props.updateQuery(queryText);
    this.props.navigateToResults({ query: queryText });
  };

  _onSubmitSearchBar = event => {
    const queryText = event.nativeEvent.text;

    insertPastQuery(queryText);
    const pastQueries = getPastQueries();
    this.props.updatePastQueries(pastQueries);

    this._onSubmit(queryText);
  };

  _renderItem = ({ item }) => {
    return (
      <ListItem
        key={item.createdAt}
        title={item.query}
        leftIcon={{ name: 'access-time' }}
        rightIcon={{ name: 'search' }}
        onPress={() => this._onSubmit(item.query)}
      />
    );
  };

  render() {
    return (
      <View style={styles.background}>
        <SearchBar
          lightTheme
          clearIcon={{ color: '#86939e', name: 'clear' }}
          textInputRef="searchInput"
          onChangeText={() => console.log('x')}
          placeholder="Search"
          onSubmitEditing={this._onSubmitSearchBar}
          autoFocus
          containerStyle={styles.searchBarContainer}
        />
        <FlatList data={this.props.pastQueries} renderItem={this._renderItem} />
      </View>
    );
  }
}

SearchStartScreen.navigationOptions = {
  title: 'Search',
  header: null,
};

SearchStartScreen.propTypes = {};

const mapStateToProps = state => {
  return {
    pastQueries: state.search.pastQueries,
  };
};

const mapDispatchToProps = dispatch => {
  return {
    updatePastQueries: pastQueries =>
      dispatch(searchUpdatePastQueries(pastQueries)),
    updateQuery: query => dispatch(searchUpdateQuery(query)),
    navigateToResults: params =>
      dispatch(
        NavigationActions.navigate({ routeName: 'SearchResults', params })
      ),
  };
};

export default connect(mapStateToProps, mapDispatchToProps)(SearchStartScreen);<commit_msg>fix touch handling on past search queries & minor tweaks (#39)<commit_after>import React from 'react';
import {
  FlatList,
  Text,
  View,
  ActivityIndicator,
  Animated,
  RefreshControl,
  Alert,
} from 'react-native';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { NavigationActions } from 'react-navigation';
import { SearchBar, ListItem } from 'react-native-elements';
import moment from 'moment';

import {
  searchUpdateQuery,
  searchUpdatePastQueries,
} from '../../actions/search';
import { insertPastQuery, getPastQueries } from '../../data/db/dbHelper';
import { styles } from './styles';

class SearchStartScreen extends React.Component {
  componentDidMount() {
    const pastQueries = getPastQueries();
    this.props.updatePastQueries(pastQueries);
  }

  _onSubmit = queryText => {
    this.props.navigateToResults({ query: queryText });
    this.props.updateQuery(queryText);
  };

  _onSubmitSearchBar = event => {
    const queryText = event.nativeEvent.text.trim();
    this._onSubmit(queryText);

    // first dispatch the navigation action, then add the query to the DB

    insertPastQuery(queryText);
    const pastQueries = getPastQueries();
    this.props.updatePastQueries(pastQueries);
  };

  _renderItem = ({ item }) => {
    return (
      <ListItem
        key={item.createdAt}
        title={item.query}
        leftIcon={{ name: 'access-time' }}
        rightIcon={{ name: 'search' }}
        onPress={() => this._onSubmit(item.query)}
      />
    );
  };

  render() {
    return (
      <View style={styles.background} keyboardShouldPersistTaps="handled">
        <SearchBar
          lightTheme
          clearIcon={{ color: '#86939e', name: 'clear' }}
          textInputRef="searchInput"
          onChangeText={() => console.log('x')}
          placeholder="Search"
          onSubmitEditing={this._onSubmitSearchBar}
          autoFocus
          autoCorrect={false}
          containerStyle={styles.searchBarContainer}
        />
        <FlatList
          data={this.props.pastQueries}
          renderItem={this._renderItem}
          keyboardShouldPersistTaps="handled"
        />
      </View>
    );
  }
}

SearchStartScreen.navigationOptions = {
  title: 'Search',
  header: null,
};

SearchStartScreen.propTypes = {};

const mapStateToProps = state => {
  return {
    pastQueries: state.search.pastQueries,
  };
};

const mapDispatchToProps = dispatch => {
  return {
    updatePastQueries: pastQueries =>
      dispatch(searchUpdatePastQueries(pastQueries)),
    updateQuery: query => dispatch(searchUpdateQuery(query)),
    navigateToResults: params =>
      dispatch(
        NavigationActions.navigate({ routeName: 'SearchResults', params })
      ),
  };
};

export default connect(mapStateToProps, mapDispatchToProps)(SearchStartScreen);
{'fraction_non_alphanumeric': 0.12907407407407406, 'fraction_numerical': 0.0022222222222222222, 'mean_word_length': 3.239403453689168, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 33, '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': '1678419', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1576, 'n_words': 311}