-
Notifications
You must be signed in to change notification settings - Fork 75
/
TopicsScreen.js
51 lines (43 loc) · 1.15 KB
/
TopicsScreen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import React, { Component } from 'react';
import { connect } from 'react-redux';
import './TopicsScreen.css';
import * as topicsActions from '../store/topics/actions';
import * as topicsSelectors from '../store/topics/reducer';
import ListView from '../components/ListView';
class TopicsScreen extends Component {
componentDidMount() {
this.props.dispatch(topicsActions.fetchTopics());
}
render() {
if (!this.props.rowsById) return this.renderLoading();
return (
<div className="TopicsScreen">
<ListView
rowsIdArray={this.props.rowsIdArray}
rowsById={this.props.rowsById}
renderRow={this.renderRow} />
</div>
);
}
renderLoading() {
return (
<p>Loading...</p>
);
}
renderRow(row) {
return (
<div>
<h3>{row.title}</h3>
<p>{row.description}</p>
</div>
)
}
}
// which props do we want to inject, given the global store state?
function mapStateToProps(state) {
return {
rowsById: topicsSelectors.getTopicsByUrl(state),
rowsIdArray: topicsSelectors.getTopicsUrlArray(state)
};
}
export default connect(mapStateToProps)(TopicsScreen);