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 11var React = require ( 'react' ) ;
22var Router = require ( 'react-router' ) ;
33var Link = Router . Link ;
4+ var Actions = require ( '../actions' ) ;
5+ var TopicStore = require ( '../stores/topic-store' ) ;
6+ var Reflux = require ( 'reflux' ) ;
47
58module . 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+ } ,
620 render : function ( ) {
721 return < nav className = "navbar navbar-default header" >
822 < div className = "container-fluid" >
923 < Link to = "/" className = "navbar-brand" >
1024 Imgur Browser
1125 </ Link >
1226 < ul className = "nav navbar-nav navbar-right" >
13- < li > < a > Topic #1 </ a > </ li >
27+ { this . renderTopics ( ) }
1428 </ ul >
1529 </ div >
1630 </ 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+ } ) ;
1745 }
1846} ) ;
Original file line number Diff line number Diff line change @@ -19,12 +19,11 @@ module.exports = React.createClass({
1919 } ,
2020 render : function ( ) {
2121 return < div className = "list-group" >
22- Topic List
2322 { this . renderTopics ( ) }
2423 </ div >
2524 } ,
2625 renderTopics : function ( ) {
27- return this . state . topics . map ( function ( topic ) {
26+ return this . state . topics . slice ( 0 , 4 ) . map ( function ( topic ) {
2827 return < Link to = { "topics/" + topic . id } className = "list-group-item" key = { topic . id } >
2928 < h4 > { topic . name } </ h4 >
3029 < p > { topic . description } </ p >
You can’t perform that action at this time.
0 commit comments