<commit_before>var React = require('react');
var $ = require('jquery');
var RoomsCollection = require('../data/collections/rooms.js');
var RoomModel = require('../data/models/room.js');
var CreateRoomModal = require('./createRoomModal.jsx');
var roomsCollection = new RoomsCollection();
var source =  window.location.origin + '/api/rooms';

var RoomsView = React.createClass({
  getInitialState: function() {
    return { errorMessage: '', showCreateRoomModal: false };
  },
  showCreateRoom: function() {
    this.setState({ showCreateRoomModal: true });
  },
  createRoomClick: function() {
    console.log('createRoom has been clicked. make sure to send a post request with the information');
    var form = document.getElementById('createRoom-form');
    var self = this;
    if (form[0].value.length > 25) { this.setState({ errorMessage: 'Your room name must be smaller than 25 characters' }); return; } 
    $.ajax({
      type: 'POST',
      url: source,
      dataType: 'JSON',
      data: {name: form[0].value},
      success: function(res) {
        self.setState({ showCreateRoomModal: false, errorMessage: '' })
        // window.location.href = '/#/room/' + res.id;
      }
    })
  },
  close: function() {
    this.setState({ showCreateRoomModal: false, errorMessage: '' });
  },
  //Event listener for changes to roomsCollection
  componentDidMount: function() {
    roomsCollection.on('change', function() {
      this.forceUpdate();
    }.bind(this));
    var self = this;
    $.get(source, function(res) {
      res.forEach(function(room) {
        //check if there 'currentMedia' is null and if it's not, create a url property for the video thumbnail
        if (room.currentMedia === null) {
          room.videoURL = '../../assets/img/no-dj.png';
          roomsCollection.add(new RoomModel(room));
        } else {
          room.videoURL = 'https://i.ytimg.com/vi/' + room.currentMedia.youtube_id + '/hqdefault.jpg';
          roomsCollection.add(new RoomModel(room));
        }
      });
      self.forceUpdate();
    })
    .fail(function() {
      console.log('error with GET request to ' + source);
    });
  },
  render: function() {
    return (
      <div>
        <a name="room"></a>
        <div className="content-section-a">
          <div className="container">
          <div className="j-createRoom-button">
            <a type="submit" className="btn btn-default btn-md" onClick={this.showCreateRoom}><i className="fa fa-pencil fa-fw"></i><span className="network-name">Create Room</span></a>
          </div>
            <div className="row j-padding-top-100px">
              { <Rooms /> }
            </div>
          </div>
          <CreateRoomModal showCreateRoomModal={this.state.showCreateRoomModal} createRoomClick={this.createRoomClick} errorMessage={this.state.errorMessage} close={this.close} />
        </div>
      </div>
    );
  }
});

var Rooms = React.createClass({
  roomClick: function(id) {
      window.location.href = '/#/room/' + id;
  },
  render: function() {
    var self = this;
    debugger
    return (<commit_msg>(fix) Creating a room will now redirect into the room without error<commit_after>var React = require('react');
var $ = require('jquery');
var RoomsCollection = require('../data/collections/rooms.js');
var RoomModel = require('../data/models/room.js');
var CreateRoomModal = require('./createRoomModal.jsx');
var roomsCollection = new RoomsCollection();
var source =  window.location.origin + '/api/rooms';

var RoomsView = React.createClass({
  getInitialState: function() {
    return { errorMessage: '', showCreateRoomModal: false };
  },
  showCreateRoom: function() {
    this.setState({ showCreateRoomModal: true });
  },
  createRoomClick: function() {
    console.log('createRoom has been clicked. make sure to send a post request with the information');
    var form = document.getElementById('createRoom-form');
    var self = this;
    if (form[0].value.length > 25) { this.setState({ errorMessage: 'Your room name must be smaller than 25 characters' }); return; } 
    $.ajax({
      type: 'POST',
      url: source,
      dataType: 'JSON',
      data: {name: form[0].value},
      success: function(res) {
        self.setState({ showCreateRoomModal: false, errorMessage: '' })
        location.reload();
        window.location.href = '/#/room/' + res.id;
      }
    })
  },
  close: function() {
    this.setState({ showCreateRoomModal: false, errorMessage: '' });
  },
  //Event listener for changes to roomsCollection
  componentDidMount: function() {
    roomsCollection.on('change', function() {
      this.forceUpdate();
    }.bind(this));
    var self = this;
    $.get(source, function(res) {
      res.forEach(function(room) {
        //check if there 'currentMedia' is null and if it's not, create a url property for the video thumbnail
        if (room.currentMedia === null) {
          room.videoURL = '../../assets/img/no-dj.png';
          roomsCollection.add(new RoomModel(room));
        } else {
          room.videoURL = 'https://i.ytimg.com/vi/' + room.currentMedia.youtube_id + '/hqdefault.jpg';
          roomsCollection.add(new RoomModel(room));
        }
      });
      self.forceUpdate();
    })
    .fail(function() {
      console.log('error with GET request to ' + source);
    });
  },
  render: function() {
    return (
      <div>
        <a name="room"></a>
        <div className="content-section-a">
          <div className="container">
          <div className="j-createRoom-button">
            <a type="submit" className="btn btn-default btn-md" onClick={this.showCreateRoom}><i className="fa fa-pencil fa-fw"></i><span className="network-name">Create Room</span></a>
          </div>
            <div className="row j-padding-top-100px">
              { <Rooms /> }
            </div>
          </div>
          <CreateRoomModal showCreateRoomModal={this.state.showCreateRoomModal} createRoomClick={this.createRoomClick} errorMessage={this.state.errorMessage} close={this.close} />
        </div>
      </div>
    );
  }
});

var Rooms = React.createClass({
  roomClick: function(id) {
      window.location.href = '/#/room/' + id;
  },
  render: function() {
    var self = this;
    return (
{'fraction_non_alphanumeric': 0.1563151982025357, 'fraction_numerical': 0.002888781896966779, 'mean_word_length': 2.8046398046398044, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 45, 'https://': 2, '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': '4873527', 'n_tokens_mistral': 1831, 'n_tokens_neox': 1818, 'n_words': 427}