2018-12-01 19:22:26 +05:30
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import testAction from '../actions/test';
|
2018-12-01 21:40:41 +05:30
|
|
|
import fetchVideos from '../actions/fetchVideos';
|
2018-12-01 19:22:26 +05:30
|
|
|
|
|
|
|
class Home extends React.Component {
|
|
|
|
clickBtn() {
|
|
|
|
this.props.testAction('some new value');
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
This is home. { this.props.test }
|
|
|
|
<div>
|
|
|
|
<Link to="/topics">Go to topics</Link>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<button onClick={ this.clickBtn.bind(this) }>Click me</button>
|
2018-12-01 21:40:41 +05:30
|
|
|
<button onClick={ this.props.fetchVideos }>Fetch videos</button>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
{ this.props.loading && 'Loading...'}
|
|
|
|
{ this.props.videos.map(video => {
|
2018-12-02 16:07:00 +02:00
|
|
|
return (<div key={ video.id }>{ video.title }</div>);
|
2018-12-01 21:40:41 +05:30
|
|
|
})}
|
2018-12-01 19:22:26 +05:30
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
2018-12-01 21:40:41 +05:30
|
|
|
test: state.home.test,
|
|
|
|
loading: state.home.loading,
|
|
|
|
videos: state.home.videos
|
2018-12-01 19:22:26 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
2018-12-01 21:40:41 +05:30
|
|
|
testAction: value => dispatch(testAction(value)),
|
|
|
|
fetchVideos: () => dispatch(fetchVideos())
|
2018-12-01 19:22:26 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Home);
|