stream-saga/src/js/components/Posts.jsx

48 lines
1 KiB
React
Raw Normal View History

2019-06-19 17:08:53 -04:00
import React, { Component } from "react"
import { connect } from "react-redux"
import { getData } from "../actions/index"
2019-06-21 10:53:16 -04:00
import { getHillaryData } from "../actions/index"
import { getTrumpData } from "../actions/index"
2019-06-19 17:08:53 -04:00
export class Post extends Component {
componentDidMount() {
2019-06-21 10:53:16 -04:00
// this.props.getData()
if (this.props.candidate === 'Hilary Clinton') {
this.props.getHillaryData()
}
else {
this.props.getTrumpData()
}
2019-06-19 17:08:53 -04:00
}
render() {
2019-06-21 00:59:25 -04:00
let cand = this.props.candidate === undefined ? 'Not set' : this.props.candidate
2019-06-19 17:08:53 -04:00
return (
2019-06-21 00:59:25 -04:00
<div>
<p>Candidate: {cand}</p>
<ul className="list-group list-group-flush">
2019-06-19 17:08:53 -04:00
{this.props.articles.map(el => (
2019-06-21 10:53:16 -04:00
<li className="list-group-item" key={el.id_str}>
<p>{el.created_at}</p>
<p>{el.text}</p>
2019-06-19 17:08:53 -04:00
</li>
))}
2019-06-21 00:59:25 -04:00
</ul>
</div>
2019-06-19 17:08:53 -04:00
)
}
}
function mapStateToProps(state) {
return {
2019-06-21 00:59:25 -04:00
articles: state.remoteArticles.slice(0, 10),
candidate: state.candidate
2019-06-19 17:08:53 -04:00
}
}
export default connect(
mapStateToProps,
2019-06-21 10:53:16 -04:00
{ getData, getHillaryData, getTrumpData }
2019-06-19 17:08:53 -04:00
)(Post)