<commit_before>﻿/**
 *  Copyright (c) 2014, Facebook, Inc.
 *  All rights reserved.
 *
 *  This source code is licensed under the BSD-style license found in the
 *  LICENSE file in the root directory of this source tree. An additional grant 
 *  of patent rights can be found in the PATENTS file in the same directory.
 *
 * @jsx React.DOM
 */

var CommentsBox = React.createClass({
	propTypes: {
		initialComments: React.PropTypes.array.isRequired,
		commentsPerPage: React.PropTypes.number.isRequired
	},
	getInitialState: function() {
		return {
			comments: this.props.initialComments,
			page: 1,
			hasMore: true
		};
	},
	loadMoreClicked: function(evt) {
		var nextPage = this.state.page + 1;
		this.setState({ page: nextPage });

		var url = evt.target.href;
		var xhr = new XMLHttpRequest();
		xhr.open('GET', url, true);
		xhr.onload = function() {
			var data = JSON.parse(xhr.responseText);
			this.setState({
				comments: this.state.comments.concat(data.comments),
				hasMore: data.hasMore
			});
		}.bind(this);
		xhr.send();
		return false;
	},
	render: function() {
		var commentNodes = this.state.comments.map(function (comment) {
			return <Comment author={comment.Author}>{comment.Text}</Comment>;
		});

		return (
			<div className="comments">
				<h1>Comments</h1>
				<ol className="commentList">
					{commentNodes}
				</ol>
				{this.renderMoreLink()}
			</div>
		);
	},
	renderMoreLink: function() {
		if (this.state.hasMore) {
			return (
				<a href={'comments/page-' + (this.state.page + 1)} onClick={this.loadMoreClicked}>
					Load More
				</a>
			);
		} else {
			return (
				<em>No more comments</em>
			);
		}
	}<commit_msg>[Sample] Show "Loading..." when loading more comments<commit_after>﻿/**
 *  Copyright (c) 2014, Facebook, Inc.
 *  All rights reserved.
 *
 *  This source code is licensed under the BSD-style license found in the
 *  LICENSE file in the root directory of this source tree. An additional grant 
 *  of patent rights can be found in the PATENTS file in the same directory.
 *
 * @jsx React.DOM
 */

var CommentsBox = React.createClass({
	propTypes: {
		initialComments: React.PropTypes.array.isRequired,
		commentsPerPage: React.PropTypes.number.isRequired
	},
	getInitialState: function() {
		return {
			comments: this.props.initialComments,
			page: 1,
			hasMore: true,
			loadingMore: false
		};
	},
	loadMoreClicked: function(evt) {
		var nextPage = this.state.page + 1;
		this.setState({
			page: nextPage,
			loadingMore: true
		});

		var url = evt.target.href;
		var xhr = new XMLHttpRequest();
		xhr.open('GET', url, true);
		xhr.onload = function() {
			var data = JSON.parse(xhr.responseText);
			this.setState({
				comments: this.state.comments.concat(data.comments),
				hasMore: data.hasMore,
				loadingMore: false
			});
		}.bind(this);
		xhr.send();
		return false;
	},
	render: function() {
		var commentNodes = this.state.comments.map(function (comment) {
			return <Comment author={comment.Author}>{comment.Text}</Comment>;
		});

		return (
			<div className="comments">
				<h1>Comments</h1>
				<ol className="commentList">
					{commentNodes}
				</ol>
				{this.renderMoreLink()}
			</div>
		);
	},
	renderMoreLink: function() {
		if (this.state.loadingMore) {
			return <em>Loading...</em>;
		} else if (this.state.hasMore) {
			return (
				<a href={'comments/page-' + (this.state.page + 1)} onClick={this.loadMoreClicked}>
					Load More
				</a>
			);
		} else {
			return <em>No more comments</em>;
		}
	}
{'fraction_non_alphanumeric': 0.14404115461560446, 'fraction_numerical': 0.005144326950557302, 'mean_word_length': 3.2892156862745097, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6188985', 'n_tokens_mistral': 1352, 'n_tokens_neox': 1160, 'n_words': 291}