File tree Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Expand file tree Collapse file tree 2 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 2
2
{
3
3
"author" : " Pete Hunt" ,
4
4
"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"
5
17
}
6
- ]
18
+ ]
Original file line number Diff line number Diff line change 37
37
if ( ! text || ! author ) {
38
38
return ;
39
39
}
40
- // TODO: send request to the server
40
+ this . props . onCommentSubmit ( { author : author , text : text } ) ;
41
41
this . refs . author . getDOMNode ( ) . value = '' ;
42
42
this . refs . text . getDOMNode ( ) . value = '' ;
43
43
} ,
66
66
} ) ;
67
67
} ,
68
68
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
+ } ) ;
70
84
} ,
71
85
getInitialState : function ( ) {
72
86
return { data : [ ] } ;
You can’t perform that action at this time.
0 commit comments