Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Current Challenge ID to be null #235

Merged
merged 8 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update comments
  • Loading branch information
bonham000 committed Sep 14, 2020
commit 2a0b037239e0166e514b28675a8a52338efec989
22 changes: 8 additions & 14 deletions packages/client/src/modules/challenges/epics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,12 @@ const challengeInitializationEpic: EpicSignature = (action$, _, deps) => {

/**
* Handle initializing the challenge context. This epic will determine an
* active challenge set based on:
* active challenge based on the current url first and the last active
* challenge second. If these don't exist, the current challenge ID will
* be null.
*
* 1) the current url
* 2) the last active challenge
* 3) by default the first challenge in the TS course
*
* NOTE: It will only result in setting a currentChallengeId if the user
* is on the workspace. Otherwise, the current challenge will be null, but
* we will still default the course and module based on the above
* considerations.
* The Redirect will only occur if user is on /workspace/ and there is an
* active challenge.
*/
const initializeChallengeStateEpic: EpicSignature = (action$, _, deps) => {
const fetchCourses$ = action$.pipe(
Expand All @@ -252,14 +248,12 @@ const initializeChallengeStateEpic: EpicSignature = (action$, _, deps) => {
const deepLinkChallengeId = findChallengeIdInLocationIfExists(location);
const activeChallengeId = deepLinkChallengeId || lastActiveId || null;
const {
challengeId,
slug,
courseId,
moduleId,
slug,
challengeId,
} = deriveIdsFromCourseWithDefaults(courses, activeChallengeId);

const currentChallenge = challengeId;

// Only redirect/update the url if they are on the workspace
if (location.pathname.includes("workspace") && slug) {
const subPath = slug + location.search + location.hash;
Expand All @@ -270,7 +264,7 @@ const initializeChallengeStateEpic: EpicSignature = (action$, _, deps) => {
Actions.setChallengeIdContext({
currentCourseId: courseId,
currentModuleId: moduleId,
currentChallengeId: currentChallenge,
currentChallengeId: challengeId,
previousChallengeId: null,
}),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/tools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ export const findChallengeIdInLocationIfExists = ({
*/
export const deriveIdsFromCourseWithDefaults = (
courses: CourseList,
maybeChallengeId: Nullable<string>,
maybeChallengeId: Nullable<string> = null,
) => {
const defaultCourse = courses[0];
const challengeMap = createInverseChallengeMapping(courses);
Expand Down