yapi/client/containers/News/News.js

59 lines
1.3 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'
// import MockDoc from '../../components/MockDoc/MockDoc.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 {
2017-07-24 16:41:11 +08:00
uid: state.user.curUid,
2017-07-17 12:15:21 +08:00
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,
2017-07-24 16:41:11 +08:00
fetchNewsData: PropTypes.func,
uid: PropTypes.string
2017-07-20 16:30:55 +08:00
}
setLoading(bool){
this.setState({
loading: bool
})
2017-07-17 12:15:21 +08:00
}
componentWillMount(){
2017-07-24 16:41:11 +08:00
console.log(this.props.uid);
this.props.fetchNewsData(107,1,10).then(function(data){
2017-07-24 16:41:11 +08:00
console.log(data);
})
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">
{/*<MockDoc />*/}
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