File tree Expand file tree Collapse file tree 2 files changed +30
-3
lines changed
imgur-client/src/components Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change 1
1
var React = require ( 'react' ) ;
2
2
var Router = require ( 'react-router' ) ;
3
3
var Link = Router . Link ;
4
+ var Actions = require ( '../actions' ) ;
5
+ var TopicStore = require ( '../stores/topic-store' ) ;
6
+ var Reflux = require ( 'reflux' ) ;
4
7
5
8
module . exports = React . createClass ( {
9
+ mixins : [
10
+ Reflux . listenTo ( TopicStore , 'onChange' )
11
+ ] ,
12
+ getInitialState : function ( ) {
13
+ return {
14
+ topics : [ ]
15
+ }
16
+ } ,
17
+ componentWillMount : function ( ) {
18
+ Actions . getTopics ( ) ;
19
+ } ,
6
20
render : function ( ) {
7
21
return < nav className = "navbar navbar-default header" >
8
22
< div className = "container-fluid" >
9
23
< Link to = "/" className = "navbar-brand" >
10
24
Imgur Browser
11
25
</ Link >
12
26
< ul className = "nav navbar-nav navbar-right" >
13
- < li > < a > Topic #1 </ a > </ li >
27
+ { this . renderTopics ( ) }
14
28
</ ul >
15
29
</ div >
16
30
</ nav >
31
+ } ,
32
+ renderTopics : function ( ) {
33
+ return this . state . topics . slice ( 0 , 4 ) . map ( function ( topic ) {
34
+ return < li key = { topic . id } >
35
+ < Link to = { "topics/" + topic . id } >
36
+ { topic . name }
37
+ </ Link >
38
+ </ li >
39
+ } ) ;
40
+ } ,
41
+ onChange : function ( event , topics ) {
42
+ this . setState ( {
43
+ topics : topics
44
+ } ) ;
17
45
}
18
46
} ) ;
Original file line number Diff line number Diff line change @@ -19,12 +19,11 @@ module.exports = React.createClass({
19
19
} ,
20
20
render : function ( ) {
21
21
return < div className = "list-group" >
22
- Topic List
23
22
{ this . renderTopics ( ) }
24
23
</ div >
25
24
} ,
26
25
renderTopics : function ( ) {
27
- return this . state . topics . map ( function ( topic ) {
26
+ return this . state . topics . slice ( 0 , 4 ) . map ( function ( topic ) {
28
27
return < Link to = { "topics/" + topic . id } className = "list-group-item" key = { topic . id } >
29
28
< h4 > { topic . name } </ h4 >
30
29
< p > { topic . description } </ p >
You can’t perform that action at this time.
0 commit comments