From c9d1495c43b0ac5bcbdaa2f724905e21a10cbc06 Mon Sep 17 00:00:00 2001 From: Sanjay Bhangar Date: Fri, 7 Dec 2018 19:25:43 +0200 Subject: [PATCH] fix bug on random topic not loading on first page load --- src/containers/Home.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/containers/Home.js b/src/containers/Home.js index c928f6e..fe607e7 100644 --- a/src/containers/Home.js +++ b/src/containers/Home.js @@ -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); } }