-
Notifications
You must be signed in to change notification settings - Fork 75
/
TopicsScreen.js
69 lines (59 loc) · 1.83 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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';
import ListRow from '../components/ListRow';
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.bind(this)} />
{!this.props.canFinalizeSelection ? false :
<button className="NextScreen" onClick={this.onNextScreenClick.bind(this)} />
}
</div>
);
}
renderLoading() {
return (
<p>Loading...</p>
);
}
renderRow(rowId, row) {
const selected = this.props.selectedIdsMap[rowId];
return (
<ListRow
rowId={rowId}
onClick={this.onRowClick.bind(this)}
selected={selected}>
<h3>{row.title}</h3>
<p>{row.description}</p>
</ListRow>
)
}
onRowClick(rowId) {
this.props.dispatch(topicsActions.selectTopic(rowId));
}
onNextScreenClick() {
this.props.dispatch(topicsActions.finalizeTopicSelection());
}
}
// which props do we want to inject, given the global store state?
function mapStateToProps(state) {
return {
rowsById: topicsSelectors.getTopicsByUrl(state),
rowsIdArray: topicsSelectors.getTopicsUrlArray(state),
selectedIdsMap: topicsSelectors.getSelectedTopicUrlsMap(state),
canFinalizeSelection: topicsSelectors.isTopicSelectionValid(state)
};
}
export default connect(mapStateToProps)(TopicsScreen);