From 53d279e3701f199afc3fcb0edb205a92b776caa0 Mon Sep 17 00:00:00 2001 From: Ben Rogers-McKee Date: Fri, 28 Jan 2022 10:06:51 +1300 Subject: [PATCH] fix: challenges navigation (#4123) * fix: challenges navigation * fix: challenges navigation alternate solution * fix: challenges navigation assert non null on find * refactor: unnecessary default value --- .../components/MDX/Challenges/Challenges.tsx | 22 +++++++++---------- .../components/MDX/Challenges/Navigation.tsx | 13 +++++------ 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/beta/src/components/MDX/Challenges/Challenges.tsx b/beta/src/components/MDX/Challenges/Challenges.tsx index 9934de66..a3a28551 100644 --- a/beta/src/components/MDX/Challenges/Challenges.tsx +++ b/beta/src/components/MDX/Challenges/Challenges.tsx @@ -97,10 +97,10 @@ export function Challenges({children, isRecipes}: ChallengesProps) { }; const currentChallenge = challenges.find(({id}) => id === activeChallenge); + if (currentChallenge === undefined) { + throw new TypeError('currentChallenge should always exist'); + } const nextChallenge = challenges.find(({order}) => { - if (!currentChallenge) { - return false; - } return order === currentChallenge.order + 1; }); @@ -121,7 +121,7 @@ export function Challenges({children, isRecipes}: ChallengesProps) { {challenges.length > 1 && (

- {isRecipes ? 'Recipe' : 'Challenge'} {currentChallenge?.order}{' '} - of {challenges.length} + {isRecipes ? 'Recipe' : 'Challenge'} {currentChallenge.order} of{' '} + {challenges.length} :
- {currentChallenge?.name} + {currentChallenge.name}

- <>{currentChallenge?.content} + <>{currentChallenge.content}
- {currentChallenge?.hint ? ( + {currentChallenge.hint ? (
)}
- {showHint && currentChallenge?.hint} + {showHint && currentChallenge.hint} {showSolution && (

Solution

- {currentChallenge?.solution} + {currentChallenge.solution}