fix bug on random topic not loading on first page load

This commit is contained in:
Sanjay Bhangar 2018-12-07 19:25:43 +02:00
parent 7d48fad50a
commit c9d1495c43

View File

@ -18,10 +18,9 @@ class Home extends React.Component {
}
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 is slightly awkward - we need to check that we have all topics,
// But don't have a random topic yet (or at not already loading a random topic)
if (this.props.allTopics && !(this.props.loadingRandomTopic || nextProps.loadingRandomTopic) && !this.props.randomTopic) {
this.props.getRandomTopicVideos(this.props.allTopics);
}
}