2018-12-05 00:49:33 +02:00
|
|
|
import React from 'react';
|
|
|
|
import {connect} from 'react-redux';
|
2018-12-07 18:59:16 +02:00
|
|
|
import { getAllTopics, getRandomTopicVideos } from '../actions/topics';
|
2018-12-05 21:48:08 +02:00
|
|
|
import Search from '../components/Search';
|
|
|
|
import Footer from '../components/Footer';
|
|
|
|
import RandomLocation from "../components/RandomLocation";
|
|
|
|
import RandomDate from "../components/RandomDate";
|
|
|
|
import RandomTopic from "../components/RandomTopic";
|
|
|
|
import Header from "../components/Header";
|
2018-12-07 18:59:16 +02:00
|
|
|
|
2018-12-01 19:22:26 +05:30
|
|
|
class Home extends React.Component {
|
2018-12-07 18:59:16 +02:00
|
|
|
componentDidMount() {
|
|
|
|
if (this.props.allTopics && this.props.allTopics.length > 0) {
|
|
|
|
this.props.getRandomTopicVideos(this.props.allTopics);
|
|
|
|
} else {
|
|
|
|
this.props.getAllTopics();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
//FIXME: this is quite ugly
|
|
|
|
// We are trying to figure out if allTopics is loaded but no request made for random topic yet,
|
|
|
|
// and then we want to load the random topic. But there should be a cleaner way to do this.
|
|
|
|
if (!nextProps.loadingAllTopics && !this.props.randomTopic && (!this.props.loadingRandomTopic || nextProps.loadingRandomTopic)) {
|
|
|
|
this.props.getRandomTopicVideos(this.props.allTopics);
|
|
|
|
}
|
2018-12-01 19:22:26 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div>
|
2018-12-07 18:59:16 +02:00
|
|
|
<RandomTopic
|
|
|
|
topicName={ this.props.randomTopic || ''}
|
|
|
|
videos = { this.props.randomTopicVideos || [] }
|
|
|
|
loading = { this.props.loadingAllTopics || this.props.loadingRandomTopic }
|
|
|
|
/>
|
2018-12-05 00:49:33 +02:00
|
|
|
<RandomLocation/>
|
|
|
|
<RandomDate/>
|
2018-12-01 19:22:26 +05:30
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
2018-12-07 18:59:16 +02:00
|
|
|
allTopics: state.topics.allTopics,
|
|
|
|
loadingAllTopics: state.topics.loadingAllTopics,
|
|
|
|
randomTopic: state.topics.randomTopic,
|
|
|
|
loadingRandomTopic: state.topics.loadingRandomTopic,
|
|
|
|
randomTopicVideos: state.topics.randomTopicVideos
|
2018-12-01 19:22:26 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
2018-12-07 18:59:16 +02:00
|
|
|
getAllTopics: () => dispatch(getAllTopics()),
|
|
|
|
getRandomTopicVideos: allTopics => dispatch(getRandomTopicVideos(allTopics))
|
2018-12-01 19:22:26 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Home);
|