From 69c2181afa233994f52f86f3c1729fc0c3f8a38b Mon Sep 17 00:00:00 2001 From: Sanjay Bhangar Date: Fri, 7 Dec 2018 19:37:57 +0200 Subject: [PATCH] add random topic items count to state --- src/containers/Home.js | 3 ++- src/reducers/topics.js | 3 ++- src/utils/get-random-topic.js | 3 +-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/containers/Home.js b/src/containers/Home.js index b426128..fa87710 100644 --- a/src/containers/Home.js +++ b/src/containers/Home.js @@ -18,7 +18,6 @@ class Home extends React.Component { } componentWillReceiveProps(nextProps) { - console.log('nextProps', nextProps); // 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 || nextProps.allTopics) && !this.props.loadingRandomTopic && !nextProps.loadingRandomTopic && !this.props.randomTopic) { @@ -31,6 +30,7 @@ class Home extends React.Component {
@@ -45,6 +45,7 @@ const mapStateToProps = state => ({ allTopics: state.topics.allTopics, loadingAllTopics: state.topics.loadingAllTopics, randomTopic: state.topics.randomTopic, + randomTopicCount: static.topics.randomTopicCount, loadingRandomTopic: state.topics.loadingRandomTopic, randomTopicVideos: state.topics.randomTopicVideos }); diff --git a/src/reducers/topics.js b/src/reducers/topics.js index 2beda0a..5866f75 100644 --- a/src/reducers/topics.js +++ b/src/reducers/topics.js @@ -25,7 +25,8 @@ export default function(state={}, action) { case LOADED_RANDOM_TOPIC: return Object.assign({}, state, { loadingRandomTopic: false, - randomTopic: action.payload.topic, + randomTopic: action.payload.topic.name, + randomTopicCount: action.payload.topic.items, randomTopicVideos: action.payload.videos }); diff --git a/src/utils/get-random-topic.js b/src/utils/get-random-topic.js index fb9796a..32c11ed 100644 --- a/src/utils/get-random-topic.js +++ b/src/utils/get-random-topic.js @@ -1,6 +1,5 @@ export default function getRandomTopic(allTopics, minVideos=4) { const validTopics = allTopics.filter(topic => topic.items >= minVideos); - console.log('valid topics', validTopics); - return validTopics[Math.floor(Math.random() * validTopics.length)].name; + return validTopics[Math.floor(Math.random() * validTopics.length)]; } \ No newline at end of file