<commit_before>import React, { Component } from 'react'

// material UI
import AutoComplete from 'material-ui/AutoComplete'

// firebase
import firebase from 'app/fire'
import 'firebase/database'

// react components
import AllUsers from './AllUsers'

export default class SearchForUser extends Component {
  constructor(props) {
    super(props)
    this.state = {
      // stores objects from call to firebase
      allStoryBranches: {},
      // stores titles to search on
      titles: [],
      // our query
      query: '',
      postive: true,
    }
    this.handleUpdateInput = this.handleUpdateInput.bind(this)
    this.handleNewRequest = this.handleNewRequest.bind(this)
    this.clearQuery = this.clearQuery.bind(this)
    this.handleSubmit = this.handleSubmit.bind(this)
  }

  componentDidMount() {
    // load all stories into state
    firebase.database().ref().child('storyBranch').on('value', snap => {
      const storyBranches = snap.val()
      this.setState({
        allStoryBranches: storyBranches,
        titles: Object.keys(storyBranches)
      }) // end set state
    })

  }

  // TODO: prevent refresh when the enter key is hit
  // displays what is being written in the search
  handleUpdateInput(query) {
    this.setState({
      query: query
    })
  }

  // update the state's query but doesn't display
  handleNewRequest(query) {
    this.setState({ query: this.state.query })
  }
  // clears the query from the searchbar
  clearQuery() { this.setState({ query: '' }) }

  handleSubmit(evt) {<commit_msg>turned off listeners in componentWillUnmount in SearchForUser<commit_after>import React, { Component } from 'react'

// material UI
import AutoComplete from 'material-ui/AutoComplete'

// firebase
import firebase from 'app/fire'
import 'firebase/database'

// react components
import AllUsers from './AllUsers'

export default class SearchForUser extends Component {
  constructor(props) {
    super(props)
    this.state = {
      // stores objects from call to firebase
      allStoryBranches: {},
      // stores titles to search on
      titles: [],
      // our query
      query: '',
      postive: true,
    }
    this.handleUpdateInput = this.handleUpdateInput.bind(this)
    this.handleNewRequest = this.handleNewRequest.bind(this)
    this.clearQuery = this.clearQuery.bind(this)
    this.handleSubmit = this.handleSubmit.bind(this)
  }

  componentDidMount() {
    // load all stories into state
    this.listenerRef = firebase.database().ref('storyBranch')
    this.listenerRef.on('value', snap => {
      const storyBranches = snap.val()
      this.setState({
        allStoryBranches: storyBranches,
        titles: Object.keys(storyBranches)
      }) // end set state
    })
  }

  componentWillUnmount() {
    this.listenerRef.off()
  }

  // TODO: prevent refresh when the enter key is hit
  // displays what is being written in the search
  handleUpdateInput(query) {
    this.setState({
      query: query
    })
  }

  // update the state's query but doesn't display
  handleNewRequest(query) {
    this.setState({ query: this.state.query })
  }
  // clears the query from the searchbar
  clearQuery() { this.setState({ query: '' }) }

  handleSubmit(evt) {
{'fraction_non_alphanumeric': 0.11131840796019901, 'fraction_numerical': 0.0, 'mean_word_length': 2.9765142150803463, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4646725', 'n_tokens_mistral': 935, 'n_tokens_neox': 931, 'n_words': 250}