<commit_before>/** @jsx React.DOM **/

var React = require('react');
var commentStore = require('../stores/commentstore.js');
var CommentList = require('./commentlist.js');
var CommentForm = require('./commentform.js');
var SortComments = require('./sortcomments.js')
var request = require('superagent');

var CommentComponent = React.createClass({
	componentWillMount: function () {
		commentStore.getCommentsList();
	},
	componentWillUnmount: function () {
	},
	loadCommentsFromServer: function (){
		var self = this;
		//TODO: send params to the url
		request.get(self.props.url).set('Accept', 'application/json').end(function(res){
			self.setState({data: res.body});
		});
	},
	handleCommentSubmit: function (comment) {
		var comments = this.state.data;
		console.log(comments);
		var newComments = comments.concat([comment]);
		this.setState({data: newComments});
		//TODO: submit to server and refresh
	},
	setConfig: function (sortOrder, key) {
		prevConfig = this.state.config;
		prevConfig[key] = sortOrder;
		this.setState({
			config: prevConfig
		});
		console.log(this.state.config);
	},
	setReply: function (replyIdVal) {
		if (!this.state.replyId) {
				this.setState({replyId: replyIdVal});
			} else {
				this.setState({replyId: null});
			}
	},
	// componentDidMount: function(){
	// 	this.loadCommentsFromServer();
	// 	setInterval(this.loadCommentsFromServer, this.props.pollInterval);
	// },
	render: function () {
		var stdComment;
		if (!this.state.replyId ) {
			stdComment = <CommentForm onCommentSubmit={this.handleCommentSubmit} replyId={this.state.replyId} />;
		}
		return(
			<div id="commentsWidget" className="comments-widget">
			<button onClick={this.setReply}> Test</button>
			<h4 className="comment-widget-title headingtooltip"><span className="comment-num">{this.state.config.commentsNumber}</span> Comments</h4>
				<section id="respond">
					{stdComment}
				</section>
				<SortComments sortBy={this.state.config.sortBy} onSendSort={this.setConfig} />
				<section id="comments" className="comment-feed" itemProp="comment">
					<CommentList config={this.state.config} data={this.state.data} handleReplyLink={this.setReply} />
				</section>
			</div>
				);
	}
});

module.exports = CommentComponent;<commit_msg>added re-render watches based on events emitted in the store. removed props off of the SortComments, they will be handled by actions and events. Moved the commentList stuff into comment component, there was no need for the other react class. <commit_after>/** @jsx React.DOM **/

var React = require('react'),
	commentStore = require('../stores/commentstore.js'),
 	CommentForm = require('./commentform.js'),
 	Comment = require('./comment.js'),
 	SortComments = require('./sortcomments.js'),
	request = require('superagent');

var CommentComponent = React.createClass({
	handleCommentSubmit: function (comment) {
		var comments = this.state.data;
		console.log(comments);
		var newComments = comments.concat([comment]);
		this.setState({data: newComments});
		//TODO: submit to server and refresh
	},
	getInitialState: function () {
		return {
			data: [],
			replyId: null,
			config: commentStore.getConfig()
		};
	},
	componentDidMount: function (){
		commentStore.getInitialData();
		// commentStore.addChangeListener(this.updateCommentList);
	},
	setReplyId: function () {
		this.setState({
			replyId: commentStore.getReplyId()
		});
	},
	updateCommentList: function () {
		this.setState({
			data: commentStore.getCommentsList()
		});
	},
	componentWillMount: function () {
		commentStore.on('comment.loaded', this.updateCommentList);
		commentStore.on('comment.added', this.updateCommentList);
		commentStore.on('comment.replyset', this.setReplyId, this.updateCommentList);
	},
	componentWillUnmount: function () {
		commentStore.off('comment.loaded', this.updateCommentList);
		commentStore.off('comment.added', this.updateCommentList);
		commentStore.off('comment.replyset', this.setReplyId, this.updateCommentList);
		// commentStore.removeChangeListener(this.updateCommentList)
	},
	render: function () {
		var stdComment;
		if (!this.state.replyId) {
			stdComment = <CommentForm onCommentSubmit={this.handleCommentSubmit} replyId={this.state.replyId} />;
		}
		return(
			<div id="commentsWidget" className="comments-widget">
			<h4 className="comment-widget-title headingtooltip"><span className="comment-num">{this.state.config.commentsNumber}</span> Comments</h4>
				<section id="respond">
					{stdComment}
				</section>
				<SortComments />
				<section id="comments" className="comment-feed" itemProp="comment">
					<ul className="media-list comment-list" >
					{this.state.data.map(function (comment, index) {
						console.log(comment);
						return (<Comment key={index} comment={comment} />);
					})}
					</ul>
				</section>
			</div>
				);
	}
});

module.exports = CommentComponent;
{'fraction_non_alphanumeric': 0.15473014570080032, 'fraction_numerical': 0.0008208495793145906, 'mean_word_length': 4.595866819747417, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '5696140', 'n_tokens_mistral': 1639, 'n_tokens_neox': 1466, 'n_words': 291}