<commit_before>'use strict'
import React from 'react'
import RoommateRow from './RoommateRow.jsx'
import Waiting from '../Mixin/Html/Waiting.jsx'
//import bindMethods from '../Mixin/Helper/Bind.js'

/* global $ */

export default class RoommateList extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      roommates: null
    }
    //bindMethods([], this)
  }

  componentDidMount() {
    this.load()
  }

  load() {
    $.getJSON('./properties/Roommate/list').done(function (data) {
      if (data.roommates) {
        this.setState({roommates: data.roommates})
      } else {
        this.setState({roommates: []})
      }
    }.bind(this))
  }

  render() {
    if (this.state.roommates === null) {
      return <Waiting label="Roommates"/>
    } else if (this.state.roommates.length === 0) {
      return <div className="well"><h2>No roommates found. Sign in and create your own!</h2></div>
    }

    let rows = this.state.roommates.map(function (value, key) {
      return (<RoommateRow roommate={value} key={key}/>)
    })

    return (
      <div>
        <h2>Roommate listing</h2>
        <div>{rows}</div>
      </div>
    )
  }
}

RoommateList.propTypes = {}<commit_msg>Searchbar added to roommate listing<commit_after>'use strict'
import React from 'react'
import RoommateRow from './RoommateRow.jsx'
import Waiting from '../Mixin/Html/Waiting.jsx'
import SearchBar from './SearchBar.jsx'
import bindMethods from '../Mixin/Helper/Bind.js'
import {profileLabel} from '../Mixin/Objects/ProfileData.js'

/* global $ */

export default class RoommateList extends React.Component {
  constructor(props) {
    super(props)
    this.state = {
      roommates: null,
      labels: {
        focus: 'College focus',
        wake_time: 'Wake up preference',
        pets: 'Pets',
        free_time: 'Spends free time',
        sleep_time: 'Bed time preference',
        smoking: 'Smoking'
      },
      searchVars: {
        focus: null,
        wake_time: null,
        sleep_time: null,
        pets: null,
        smoking: null,
        free_time: null
      }
    }
    bindMethods([
      'updateSearchVars', 'reset'
    ], this)
  }

  componentDidMount() {
    this.load()
  }

  reset() {
    this.defaultLabels()
    this.clearVars()
  }

  clearVars() {
    const searchVars = {
      focus: null,
      wake_time: null,
      sleep_time: null,
      pets: null,
      smoking: null,
      free_time: null
    }
    this.setState({searchVars: searchVars}, this.load)
  }

  defaultLabels() {
    const labels = {
      focus: 'College focus',
      wake_time: 'Wake up preference',
      pets: 'Pets',
      free_time: 'Spends free time',
      sleep_time: 'Bed time preference',
      smoking: 'Smoking'
    }
    this.setState({labels: labels})
  }

  updateSearchVars(varname, value) {
    let searchVars = this.state.searchVars
    let labels = this.state.labels
    searchVars[varname] = value
    labels[varname] = profileLabel[varname][value]
    this.setState({searchVars: searchVars, labels: labels}, this.load)
  }

  load() {
    $.getJSON('./properties/Roommate/list', this.state.searchVars).done(function (data) {
      if (data.roommates) {
        this.setState({roommates: data.roommates})
      } else {
        this.setState({roommates: []})
      }
    }.bind(this))
  }

  render() {
    let rows

    if (this.state.roommates === null) {
      return <Waiting label="Roommates"/>
    } else if (this.state.roommates.length === 0) {
      rows = <div className="well">
        <p>No roommates found.</p>
      </div>
    } else {
      rows = this.state.roommates.map(function (value, key) {
        return (<RoommateRow roommate={value} key={key}/>)
      })
    }

    return (
      <div>
        <h2>Roommate listing</h2>
        <SearchBar
          updateSearchVars={this.updateSearchVars}
          searchVars={this.state.searchVars}
          labels={this.state.labels}
          reset={this.reset}/>
        <div>{rows}</div>
      </div>
    )
  }
}

RoommateList.propTypes = {}
{'fraction_non_alphanumeric': 0.1437731196054254, 'fraction_numerical': 0.001972872996300863, 'mean_word_length': 2.4285714285714284, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, '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': '4998606', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1321, 'n_words': 277}