<commit_before>"use strict";

var SlackLogViewer = React.createClass({
  getInitialState: function() {
    return {
      logs: [],
      members: [],
      channels: [],
      currentChannel: null
    };
  },
  componentDidMount: function() {
    var self = this;
    var time = (new Date()).getTime();
    $.when(
      $.get('/channels.json?t=' + time),
      $.get('/members.json?t=' + time),
      $.get('/logs.json?t=' + time)
    ).done(function(channels, members, logs) {
      self.setState({
        channels: channels[0],
        members: members[0],
        logs: logs[0]
      });
    })
  },
  changeCurrentChannel: function(channel) {
    this.setState({
      currentChannel: channel
    });
  },
  render: function() {
    return (
      <div>
        <SlackChannels channels={this.state.channels}
          changeCurrentChannel={this.changeCurrentChannel}
          currentChannel={this.state.currentChannel} />
        <SlackMessages members={this.state.members} logs={this.state.logs}
          currentChannel={this.state.currentChannel} />
      </div>
    );
  }
});

var SlackChannel = React.createClass({
  handleClick: function() {
    this.props.handleClick(this.props.channel.id);
  },
  render: function() {
    return <p onClick={this.handleClick}>{this.props.channel.name}</p>
  }
});

var SlackChannels = React.createClass({
  render: function() {
    var self = this;
    var createChannelList = function(channels) {
      return _.map(channels, function(channel) {
        var classNames = [];
        if (self.props.currentChannel === channel.id) {
          classNames.push('selected');
        }
        return (
          <li className={classNames.join(' ')}>
            <SlackChannel channel={channel}
              handleClick={self.props.changeCurrentChannel} />
          </li>
        );
      });
    };
    return (
      <ul className="slack-channels">
        {createChannelList(this.props.channels)}
      </ul>
    );
  }
});

var SlackMember = React.createClass({
  render: function() {
    return (
      <p>{this.props.member.name}</p>
    );
  }
});

var SlackMessage = React.createClass({
  member: function() {
    return this.props.members[this.props.message.user];
  },
  formatedDate: function() {
    return new Date(this.props.message.posted_at * 1000).toLocaleString();
  },
  render: function() {
    return (
      <div className="slack-message">
        <div className="slack-message-member-image">
          <img src={this.member() && this.member().profile.image_32} />
        </div>
        <div className="slack-message-content">
          <div className="slack-message-member-name">{this.member() && this.member().name}</div>
          <div className="slack-message-date">{this.formatedDate()}</div>
          <div className="slack-message-text">{this.props.message.text}</div>
        </div>
      </div>
    );
  }
});

var SlackMessages = React.createClass({
  render: function() {
    var self = this;
    var createMessage = function(messages, i) {
      return _.map(messages, function(message) {
        return <SlackMessage message={message} members={self.props.members} />;
      });
    };
    return (<commit_msg>format reply<commit_after>"use strict";

var SlackLogViewer = React.createClass({
  getInitialState: function() {
    return {
      logs: [],
      members: [],
      channels: [],
      currentChannel: null
    };
  },
  componentDidMount: function() {
    var self = this;
    var time = (new Date()).getTime();
    $.when(
      $.get('/channels.json?t=' + time),
      $.get('/members.json?t=' + time),
      $.get('/logs.json?t=' + time)
    ).done(function(channels, members, logs) {
      self.setState({
        channels: channels[0],
        members: members[0],
        logs: logs[0]
      });
    })
  },
  changeCurrentChannel: function(channel) {
    this.setState({
      currentChannel: channel
    });
  },
  render: function() {
    return (
      <div>
        <SlackChannels channels={this.state.channels}
          changeCurrentChannel={this.changeCurrentChannel}
          currentChannel={this.state.currentChannel} />
        <SlackMessages members={this.state.members} logs={this.state.logs}
          currentChannel={this.state.currentChannel} />
      </div>
    );
  }
});

var SlackChannel = React.createClass({
  handleClick: function() {
    this.props.handleClick(this.props.channel.id);
  },
  render: function() {
    return <p onClick={this.handleClick}>{this.props.channel.name}</p>
  }
});

var SlackChannels = React.createClass({
  render: function() {
    var self = this;
    var createChannelList = function(channels) {
      return _.map(channels, function(channel) {
        var classNames = [];
        if (self.props.currentChannel === channel.id) {
          classNames.push('selected');
        }
        return (
          <li className={classNames.join(' ')}>
            <SlackChannel channel={channel}
              handleClick={self.props.changeCurrentChannel} />
          </li>
        );
      });
    };
    return (
      <ul className="slack-channels">
        {createChannelList(this.props.channels)}
      </ul>
    );
  }
});

var SlackMember = React.createClass({
  render: function() {
    return (
      <p>{this.props.member.name}</p>
    );
  }
});

var SlackMessage = React.createClass({
  member: function() {
    return this.props.members[this.props.message.user];
  },
  formatDate: function(date) {
    return new Date(date * 1000).toLocaleString();
  },
  formatText: function(text) {
    return text.replace(/<@[0-9A-Za-z]+\|([0-9A-Za-z]+)>/gi, "@$1");
  },
  render: function() {
    return (
      <div className="slack-message">
        <div className="slack-message-member-image">
          <img src={this.member() && this.member().profile.image_32} />
        </div>
        <div className="slack-message-content">
          <div className="slack-message-member-name">{this.member() && this.member().name}</div>
          <div className="slack-message-date">{this.formatDate(this.props.message.posted_at)}</div>
          <div className="slack-message-text">{this.formatText(this.props.message.text)}</div>
        </div>
      </div>
    );
  }
});

var SlackMessages = React.createClass({
  render: function() {
    var self = this;
    var createMessage = function(messages, i) {
      return _.map(messages, function(message) {
        return <SlackMessage message={message} members={self.props.members} />;
      });
    };
    return (
{'fraction_non_alphanumeric': 0.16541237905083706, 'fraction_numerical': 0.003532483489479343, 'mean_word_length': 2.578021978021978, 'pattern_counts': {'":': 0, '<': 58, '<?xml version=': 0, '>': 58, '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': '4578230', 'n_tokens_mistral': 1992, 'n_tokens_neox': 1980, 'n_words': 330}