yapi/client/containers/News/News.js

52 lines
1.1 KiB
JavaScript
Raw Normal View History

2017-07-17 12:15:21 +08:00
import './News.scss'
import React, { Component } from 'react'
import NewsTimeline from './NewsTimeline/NewsTimeline'
import { connect } from 'react-redux'
import PropTypes from 'prop-types'
import NewsList from './NewsList/NewsList.js'
2017-07-20 16:30:55 +08:00
import { fetchNewsData } from '../../actions/news.js'
2017-07-17 12:15:21 +08:00
@connect(
state => {
return {
newsData: state.news.newsData?state.news.newsData:[]
}
},
{
2017-07-20 16:30:55 +08:00
fetchNewsData: fetchNewsData
2017-07-17 12:15:21 +08:00
}
)
class News extends Component {
constructor(props) {
super(props)
2017-07-20 16:30:55 +08:00
this.state = {
loading: false
}
2017-07-17 12:15:21 +08:00
}
static propTypes = {
2017-07-20 16:30:55 +08:00
newsData: PropTypes.object,
fetchNewsData: PropTypes.func
}
setLoading(bool){
this.setState({
loading: bool
})
2017-07-17 12:15:21 +08:00
}
componentWillMount(){
2017-07-20 16:30:55 +08:00
this.props.fetchNewsData()
2017-07-17 12:15:21 +08:00
}
render () {
2017-07-17 18:15:55 +08:00
const data = this.props.newsData
2017-07-17 12:15:21 +08:00
return (
<section className="news-box">
2017-07-20 16:30:55 +08:00
<NewsList loading={this.state.loading} setLoading={this.setLoading.bind(this)} />
<NewsTimeline loading={this.state.loading} setLoading={this.setLoading.bind(this)} newsData = {data} />
2017-07-17 12:15:21 +08:00
</section>
)
}
}
export default News