Skip to content

Commit 6680a3a

Browse files
committed
Flux - 18 - Rendering Topics in the Header
1 parent fcfe2fc commit 6680a3a

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed
Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,46 @@
11
var React = require('react');
22
var Router = require('react-router');
33
var Link = Router.Link;
4+
var Actions = require('../actions');
5+
var TopicStore = require('../stores/topic-store');
6+
var Reflux = require('reflux');
47

58
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+
},
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
});

imgur-client/src/components/topic-list.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff 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>

0 commit comments

Comments
 (0)