<commit_before>var React = require('react')
import _ from 'lodash'
import UserStore from '../stores/UserStore.js'

var ChatWebsocket = require('./ChatWebsocket')
var userAuth = require('../userAuth')

export default class ChatInput extends React.Component {
    constructor() {
      super()

      this.state = {
        input: '',
        sending: false,
        users: [],
      }
    }

    componentDidMount() {
      UserStore.listen((data) => {
        this.setState({
          users: _.filter(data, (user) => {
            return user.online
          })
        })
      })
    }

    _inputChange(event) {
      this.setState({
        input: event.target.value,
      })
    }

    _keyDown(event) {
      if (event.keyCode === 13) {
        event.preventDefault()
        if(this.state.input.trim() !== ''){
          this._send()
          _.defer(() => {
            this.state.input = ''
            this.refs.input.value = ''
          })
        }
      }
      if (event.keyCode === 9) {
        event.preventDefault()
        var currentMessage = this.state.input.split(" ")
        for(var i = 0; i < this.state.users.length; i++){
          if(this.state.users[i].username.indexOf(currentMessage[currentMessage.length - 1]) == 0){
            currentMessage[currentMessage.length - 1] = this.state.users[i].username
            this.refs.input.value = currentMessage.join(' ')
            this.state.input = this.refs.input.value
            return
          }
        }
      }
    }

    _send() {
      userAuth.getUser()
        .then((user) => {
          ChatWebsocket.send(user.id, this.state.input)
        })
    }

    render(){
      return (
        <div id='chat-input'>
          <div className="avatar"></div>
          <textarea
            ref='input'
            onChange={this._inputChange.bind(this)}
            onKeyDown={this._keyDown.bind(this)}
            placeholder="Shitpost here" />
        </div>
      )
    }
}<commit_msg>refactor username autofill a bit<commit_after>var React = require('react')
import _ from 'lodash'
import UserStore from '../stores/UserStore.js'

var ChatWebsocket = require('./ChatWebsocket')
var userAuth = require('../userAuth')


const RETURN_KEYCODE = 13
const TAB_KEYCODE = 9

export default class ChatInput extends React.Component {
    constructor() {
      super()

      this.state = {
        input: '',
        sending: false,
        users: [],
      }
    }

    componentDidMount() {
      UserStore.listen((data) => {
        this.setState({
          users: _.filter(data, (user) => {
            return user.online
          })
        })
      })
    }

    _keyDown(event) {
      if (event.keyCode === RETURN_KEYCODE) {
        event.preventDefault()
        this._send()
        return
      }
      if (event.keyCode === TAB_KEYCODE) {
        event.preventDefault()
        var currentMessage = this.refs.input.value.split(" ")
        var lastToken = currentMessage[currentMessage.length - 1]
        if (lastToken.trim() === '') {
          return
        }
        _.each(this.state.users, (user) => {
          if (user.username.indexOf(lastToken) === 0) {
            currentMessage[currentMessage.length - 1] = user.username
          }
          this.refs.input.value = currentMessage.join(' ')
        })
      }
    }

    _send() {
      let message = this.refs.input.value.trim()
      if (message === '') {
        return
      }
      this.refs.input.value = ''

      userAuth.getUser()
        .then((user) => {
          ChatWebsocket.send(user.id, message)
        })
    }

    render(){
      return (
        <div id='chat-input'>
          <div className="avatar"></div>
          <textarea
            ref='input'
            onKeyDown={this._keyDown.bind(this)}
            placeholder="Shitpost here" />
        </div>
      )
    }
}
{'fraction_non_alphanumeric': 0.144116122343183, 'fraction_numerical': 0.00336962156557802, 'mean_word_length': 1.7195207892882312, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 21, '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': '6248028', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1127, 'n_words': 195}