Fix(nav): current-challenge should work when not on challenges
This commit is contained in:
@ -52,10 +52,13 @@ export function loadCurrentChallengeSaga(actions, getState) {
|
|||||||
const state = getState();
|
const state = getState();
|
||||||
const {
|
const {
|
||||||
entities: { challenge: challengeMap, challengeIdToName },
|
entities: { challenge: challengeMap, challengeIdToName },
|
||||||
challengesApp: { id: currentlyLoadedChallengeId }
|
challengesApp: { id: currentlyLoadedChallengeId },
|
||||||
|
locationBeforeTransition: { pathname } = {}
|
||||||
} = state;
|
} = state;
|
||||||
const firstChallenge = firstChallengeSelector(state);
|
const firstChallenge = firstChallengeSelector(state);
|
||||||
const { user: { currentChallengeId } } = userSelector(state);
|
const { user: { currentChallengeId } } = userSelector(state);
|
||||||
|
const isOnAChallenge = (/^\/[^\/]{2,6}\/challenges/).test(pathname);
|
||||||
|
|
||||||
if (!currentChallengeId) {
|
if (!currentChallengeId) {
|
||||||
finalChallenge = firstChallenge;
|
finalChallenge = firstChallenge;
|
||||||
} else {
|
} else {
|
||||||
@ -63,11 +66,12 @@ export function loadCurrentChallengeSaga(actions, getState) {
|
|||||||
challengeIdToName[ currentChallengeId ]
|
challengeIdToName[ currentChallengeId ]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
// challenge data may not be set yet.
|
if (
|
||||||
if (!finalChallenge.id) {
|
// data might not be there yet, ignore for now
|
||||||
return Observable.empty();
|
!finalChallenge ||
|
||||||
}
|
// are we already on that challenge?
|
||||||
if (finalChallenge.id === currentlyLoadedChallengeId) {
|
(isOnAChallenge && finalChallenge.id === currentlyLoadedChallengeId)
|
||||||
|
) {
|
||||||
// don't reload if the challenge is already loaded.
|
// don't reload if the challenge is already loaded.
|
||||||
// This may change to toast to avoid user confusion
|
// This may change to toast to avoid user confusion
|
||||||
return Observable.empty();
|
return Observable.empty();
|
||||||
|
Reference in New Issue
Block a user