1
1
var React = require ( 'react' ) ;
2
2
var Reflux = require ( 'reflux' ) ;
3
3
var ImageStore = require ( '../stores/image-store' ) ;
4
+ var CommentStore = require ( '../stores/comment-store' ) ;
4
5
var Actions = require ( '../actions' ) ;
6
+ var CommentBox = require ( './comment-box' ) ;
5
7
6
8
module . exports = React . createClass ( {
7
9
mixins : [
8
- Reflux . listenTo ( ImageStore , 'onChange' )
10
+ Reflux . listenTo ( ImageStore , 'onChange' ) ,
11
+ Reflux . listenTo ( CommentStore , 'onChange' )
9
12
] ,
10
13
getInitialState : function ( ) {
11
14
return {
12
- image : null
15
+ image : null ,
16
+ comment : null
13
17
}
14
18
} ,
15
19
componentWillMount : function ( ) {
@@ -33,8 +37,17 @@ module.exports = React.createClass({
33
37
< h5 > { this . state . image . description } </ h5 >
34
38
</ div >
35
39
</ div >
40
+ < h3 > Comments</ h3 >
41
+ { this . renderComments ( ) }
36
42
</ div >
37
43
} ,
44
+ renderComments : function ( ) {
45
+ if ( ! this . state . comments ) {
46
+ return null
47
+ }
48
+
49
+ return < CommentBox comments = { this . state . comments } />
50
+ } ,
38
51
renderImage : function ( ) {
39
52
if ( this . state . image . animated ) {
40
53
return < video preload = "auto" autoPlay = "autoplay" loop = "loop" webkit-playsinline >
@@ -46,7 +59,8 @@ module.exports = React.createClass({
46
59
} ,
47
60
onChange : function ( ) {
48
61
this . setState ( {
49
- image : ImageStore . find ( this . props . params . id )
62
+ image : ImageStore . find ( this . props . params . id ) ,
63
+ comments : CommentStore . comment
50
64
} ) ;
51
65
}
52
66
} ) ;
0 commit comments