<commit_before>import React from 'react';
import firebase, { reference, signIn } from '../firebase';
import MessageInput  from './MessageInput';
import { RenderMessages } from './RenderMessages';
import FilterBar from './FilterBar';
import { Login } from './Login';


export default class Application extends React.Component {
  constructor() {
    super();
    this.state = {
      messagesArray: [],
      searchResults: null,
      user: null,
      currentDirection: 'down',
    };
  }

  componentDidMount() {
    firebase.database().ref('messages').on('value', (snapshot) => {
      const messagesFromFirebase = this.createArray(snapshot.val());
      this.setState({ messagesArray: messagesFromFirebase });
    });
  }

  createArray(object) {
    const firebaseKeys = object ? Object.keys(object) : [];
    const messages = [];
    firebaseKeys.map((key) => {
      const singleMessage = object[key];
      singleMessage['firebaseId'] = key;
      messages.push(singleMessage);
    });
    return messages;
  }

  displayMessage(message) {
    const addDataToObj = Object.assign(message,
      { id: Date.now() },
      { userName: this.state.user.displayName },
      { usersEmail: this.state.user.email });
    firebase.database().ref('messages').push(addDataToObj);
    this.state.messagesArray.push(addDataToObj);
    this.setState({ messagesArray: this.state.messagesArray });
  }

  handleSort(newDirection) {
    if (newDirection !== this.state.currentDirection) {
      this.state.searchResults.reverse();
      const sortedArray = this.state.messagesArray.reverse();
      this.setState({ messagesArray: sortedArray, currentDirection: newDirection });
    }
  }

  handleSearch(search) {
    let searchResults = this.state.messagesArray.filter((object) => {
      return object.input.indexOf(search) >= 0;
    });
    this.setState({ searchResults });
  }

  render() {
    return (
      <div className='application'>
        <FilterBar
          handleSort={this.handleSort.bind(this)}
          handleSearch={this.handleSearch.bind(this)}<commit_msg>Fix another bug with sorting and searching<commit_after>import React from 'react';
import firebase, { reference, signIn } from '../firebase';
import MessageInput  from './MessageInput';
import { RenderMessages } from './RenderMessages';
import FilterBar from './FilterBar';
import { Login } from './Login';


export default class Application extends React.Component {
  constructor() {
    super();
    this.state = {
      messagesArray: [],
      searchResults: null,
      user: null,
      currentDirection: 'down',
    };
  }

  componentDidMount() {
    firebase.database().ref('messages').on('value', (snapshot) => {
      const messagesFromFirebase = this.createArray(snapshot.val());
      this.setState({ messagesArray: messagesFromFirebase });
    });
  }

  createArray(object) {
    const firebaseKeys = object ? Object.keys(object) : [];
    const messages = [];
    firebaseKeys.map((key) => {
      const singleMessage = object[key];
      singleMessage['firebaseId'] = key;
      messages.push(singleMessage);
    });
    return messages;
  }

  displayMessage(message) {
    const addDataToObj = Object.assign(message,
      { id: Date.now() },
      { userName: this.state.user.displayName },
      { usersEmail: this.state.user.email });
    firebase.database().ref('messages').push(addDataToObj);
    this.state.messagesArray.push(addDataToObj);
    this.setState({ messagesArray: this.state.messagesArray });
  }

  handleSort(newDirection) {
    if (newDirection !== this.state.currentDirection && this.state.searchResults) {
      const sortedArray = this.state.searchResults.reverse();
      this.setState({ searchResults: sortedArray, currentDirection: newDirection });
    } else if (newDirection !== this.state.currentDirection) {
      const sortedArray = this.state.messagesArray.reverse();
      this.setState({ messagesArray: sortedArray, currentDirection: newDirection });
    }
  }

  handleSearch(search) {
    let searchResults = this.state.messagesArray.filter((object) => {
      return object.input.indexOf(search) >= 0;
    });
    this.setState({ searchResults });
  }

  render() {
    return (
      <div className='application'>
        <FilterBar
          handleSort={this.handleSort.bind(this)}
          handleSearch={this.handleSearch.bind(this)}
{'fraction_non_alphanumeric': 0.1399770904925544, 'fraction_numerical': 0.0004581901489117984, 'mean_word_length': 3.4279918864097363, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '1528613', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1211, 'n_words': 239}