1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- 'use strict';
- var React = require('react');
- var converter = new Showdown.converter();
- var Comment = React.createClass({
- render: function() {
- var rawMarkup = converter.makeHtml(this.props.children.toString());
- return (
- <div className="comment">
- <h2 className="commentAuthor">
- {this.props.author}
- </h2>
- <span dangerouslySetInnerHTML={{__html: rawMarkup}} />
- </div>
- );
- }
- });
- var CommentList = React.createClass({
- render: function () {
- var commentNodes = this.props.data.map(function(comment) {
- return (
- <Comment author={comment.author}>
- {comment.text}
- </Comment>
- );
- });
- return (
- <div className="commentList" >
- {commentNodes}
- </div>
- );
- }
- });
- var CommentForm = React.createClass({
- render: function() {
- return (
- <div className="commentForm">
- Hello, world! I am a CommentForm.
- </div>
- );
- }
- });
- var CommentBox = React.createClass({
- getInitialState: function() {
- return {data: []};
- },
- componentDidMount: function() {
- $.ajax({
- url: this.props.url,
- dataType: 'json',
- success: function(data) {
- this.setState({data: data});
- }.bind(this),
- error: function(xhr, status, err) {
- console.error(this.props.url, status, err.toString());
- }.bind(this)
- });
- },
- render() {
- return (
- <div className="commentBox" >
- <h1>Comments</h1>
- <CommentList data={this.state.data} />
- <CommentForm />
- </div>
- );
- }
- });
- module.exports = CommentBox;
|