From 879f5b3bb8eff4864dbfba8f4b8e6846260d78c9 Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Thu, 4 Aug 2016 15:16:55 -0700 Subject: [PATCH] Fix(nav): current-challenge should work when not on challenges --- common/app/redux/load-current-challenge-saga.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/common/app/redux/load-current-challenge-saga.js b/common/app/redux/load-current-challenge-saga.js index d90cf8e853..6068f4d646 100644 --- a/common/app/redux/load-current-challenge-saga.js +++ b/common/app/redux/load-current-challenge-saga.js @@ -52,10 +52,13 @@ export function loadCurrentChallengeSaga(actions, getState) { const state = getState(); const { entities: { challenge: challengeMap, challengeIdToName }, - challengesApp: { id: currentlyLoadedChallengeId } + challengesApp: { id: currentlyLoadedChallengeId }, + locationBeforeTransition: { pathname } = {} } = state; const firstChallenge = firstChallengeSelector(state); const { user: { currentChallengeId } } = userSelector(state); + const isOnAChallenge = (/^\/[^\/]{2,6}\/challenges/).test(pathname); + if (!currentChallengeId) { finalChallenge = firstChallenge; } else { @@ -63,11 +66,12 @@ export function loadCurrentChallengeSaga(actions, getState) { challengeIdToName[ currentChallengeId ] ]; } - // challenge data may not be set yet. - if (!finalChallenge.id) { - return Observable.empty(); - } - if (finalChallenge.id === currentlyLoadedChallengeId) { + if ( + // data might not be there yet, ignore for now + !finalChallenge || + // are we already on that challenge? + (isOnAChallenge && finalChallenge.id === currentlyLoadedChallengeId) + ) { // don't reload if the challenge is already loaded. // This may change to toast to avoid user confusion return Observable.empty();