2019-06-19 17:08:53 -04:00
|
|
|
import React, { Component } from "react"
|
|
|
|
import { connect } from "react-redux"
|
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 {
|
2019-06-21 11:51:07 -04:00
|
|
|
componentWillUpdate(nextProps, nextState) {
|
|
|
|
if (nextProps.candidate !== this.props.candidate) {
|
|
|
|
if (nextProps.candidate === 'Hillary Clinton') {
|
|
|
|
this.props.getHillaryData()
|
|
|
|
}
|
|
|
|
else if (nextProps.candidate === 'Donald Trump'){
|
|
|
|
this.props.getTrumpData()
|
|
|
|
}
|
2019-06-21 10:53:16 -04:00
|
|
|
}
|
2019-06-21 11:51:07 -04:00
|
|
|
}
|
2019-06-19 17:08:53 -04:00
|
|
|
|
2019-06-21 11:51:07 -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>
|
2019-06-21 11:51:07 -04:00
|
|
|
<p>@{cand}</p>
|
2019-06-21 00:59:25 -04:00
|
|
|
<ul className="list-group list-group-flush">
|
2019-06-21 11:51:07 -04:00
|
|
|
{this.props.articles.map(el => (
|
|
|
|
<li className="list-group-item" key={el.id_str}>
|
|
|
|
<p>{el.created_at}</p>
|
|
|
|
<p>{el.text}</p>
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
2019-06-19 17:08:53 -04:00
|
|
|
)
|
2019-06-21 11:51:07 -04:00
|
|
|
}
|
2019-06-19 17:08:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
2019-06-21 11:51:07 -04:00
|
|
|
return {
|
2019-06-21 00:59:25 -04:00
|
|
|
articles: state.remoteArticles.slice(0, 10),
|
|
|
|
candidate: state.candidate
|
2019-06-21 11:51:07 -04:00
|
|
|
}
|
2019-06-19 17:08:53 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(
|
2019-06-21 11:51:07 -04:00
|
|
|
mapStateToProps,
|
|
|
|
{ getHillaryData, getTrumpData }
|
2019-06-19 17:08:53 -04:00
|
|
|
)(Post)
|