Skip to content

Commit 9d500da

Browse files
committed
Working through tutorial
1 parent 71bb1ad commit 9d500da

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

comments.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,17 @@
22
{
33
"author": "Pete Hunt",
44
"text": "Hey tccchere!"
5+
},
6+
{
7+
"author": "TreeBeard",
8+
"text": "HatHat"
9+
},
10+
{
11+
"author": "asd",
12+
"text": "asdasda"
13+
},
14+
{
15+
"author": "asd",
16+
"text": "asdasdas"
517
}
6-
]
18+
]

tutorial/index.html

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
if (!text || !author) {
3838
return;
3939
}
40-
// TODO: send request to the server
40+
this.props.onCommentSubmit({author: author, text: text});
4141
this.refs.author.getDOMNode().value = '';
4242
this.refs.text.getDOMNode().value = '';
4343
},
@@ -66,7 +66,21 @@
6666
});
6767
},
6868
handleCommentSubmit: function(comment) {
69-
// TODO: submit to the server and refresh the list
69+
var comments = this.state.data;
70+
var newComments = comments.concat([comment]);
71+
this.setState({data: newComments});
72+
$.ajax({
73+
url: this.props.url,
74+
dataType: 'json',
75+
type: 'POST',
76+
data: comment,
77+
success: function(data) {
78+
this.setState({data: data});
79+
}.bind(this),
80+
error: function(xhr, status, err) {
81+
console.error(this.props.url, status, err.toString());
82+
}.bind(this)
83+
});
7084
},
7185
getInitialState: function() {
7286
return {data: []};

0 commit comments

Comments
 (0)