refactor(client): get next/prev paths directly from redux (#57434)

This commit is contained in:
Oliver Eyton-Williams
2024-12-07 08:54:45 +01:00
committed by GitHub
parent c407c4a5bf
commit f9a8f08022
10 changed files with 14 additions and 54 deletions
@@ -204,7 +204,7 @@ function ShowClassic({
},
pageContext: {
challengeMeta,
challengeMeta: { isFirstStep, nextChallengePath, prevChallengePath },
challengeMeta: { isFirstStep, nextChallengePath },
projectPreview: { challengeData }
},
createFiles,
@@ -445,8 +445,6 @@ function ShowClassic({
executeChallenge={executeChallenge}
containerRef={containerRef}
instructionsPanelRef={instructionsPanelRef}
nextChallengePath={nextChallengePath}
prevChallengePath={prevChallengePath}
usesMultifileEditor={usesMultifileEditor}
editorRef={editorRef}
>
@@ -130,9 +130,6 @@ function ShowCodeAlly(props: ShowCodeAllyProps) {
},
isChallengeCompleted,
isSignedIn,
pageContext: {
challengeMeta: { nextChallengePath, prevChallengePath }
},
partiallyCompletedChallenges,
t,
updateSolutionFormValues
@@ -260,11 +257,7 @@ function ShowCodeAlly(props: ShowCodeAllyProps) {
};
return (
<Hotkeys
containerRef={container}
nextChallengePath={nextChallengePath}
prevChallengePath={prevChallengePath}
>
<Hotkeys containerRef={container}>
<LearnLayout>
<Helmet title={windowTitle} />
<Container>
@@ -3,13 +3,13 @@ import React from 'react';
import { HotKeys, GlobalHotKeys } from 'react-hotkeys';
import { connect } from 'react-redux';
import { createSelector } from 'reselect';
import type {
ChallengeFiles,
Test,
User,
ChallengeMeta
} from '../../../redux/prop-types';
import { userSelector } from '../../../redux/selectors';
import {
setEditorFocusability,
@@ -20,6 +20,7 @@ import {
import {
canFocusEditorSelector,
challengeFilesSelector,
challengeMetaSelector,
challengeTestsSelector,
isHelpModalOpenSelector,
isProjectPreviewModalOpenSelector,
@@ -39,6 +40,7 @@ const mapStateToProps = createSelector(
challengeFilesSelector,
challengeTestsSelector,
userSelector,
challengeMetaSelector,
(
isHelpModalOpen: boolean,
isResetModalOpen: boolean,
@@ -47,7 +49,8 @@ const mapStateToProps = createSelector(
canFocusEditor: boolean,
challengeFiles: ChallengeFiles,
tests: Test[],
user: User
user: User,
{ nextChallengePath, prevChallengePath }: ChallengeMeta
) => ({
isHelpModalOpen,
isResetModalOpen,
@@ -56,7 +59,9 @@ const mapStateToProps = createSelector(
canFocusEditor,
challengeFiles,
tests,
user
user,
nextChallengePath,
prevChallengePath
})
);
@@ -164,9 +164,6 @@ function ShowExam(props: ShowExamProps) {
isChallengeCompleted,
openExitExamModal,
openFinishExamModal,
pageContext: {
challengeMeta: { nextChallengePath, prevChallengePath }
},
t
} = props;
@@ -485,11 +482,7 @@ function ShowExam(props: ShowExamProps) {
</Row>
</Container>
) : (
<Hotkeys
containerRef={container}
nextChallengePath={nextChallengePath}
prevChallengePath={prevChallengePath}
>
<Hotkeys containerRef={container}>
<LearnLayout>
<Helmet title={windowTitle} />
<Container>
@@ -178,8 +178,6 @@ const ShowFillInTheBlank = ({
<Hotkeys
executeChallenge={() => handleSubmit()}
containerRef={container}
nextChallengePath={challengeMeta.nextChallengePath}
prevChallengePath={challengeMeta.prevChallengePath}
playScene={() => handlePlayScene(true)}
>
<LearnLayout>
@@ -96,7 +96,6 @@ const ShowGeneric = ({
isChallengeCompleted
}: ShowQuizProps) => {
const { t } = useTranslation();
const { nextChallengePath, prevChallengePath } = challengeMeta;
const container = useRef<HTMLElement | null>(null);
const blockNameTitle = `${t(
@@ -176,8 +175,6 @@ const ShowGeneric = ({
<Hotkeys
executeChallenge={handleSubmit}
containerRef={container}
nextChallengePath={nextChallengePath}
prevChallengePath={prevChallengePath}
playScene={scene ? () => setIsScenePlaying(true) : undefined}
>
<LearnLayout>
@@ -145,9 +145,6 @@ function MsTrophy(props: MsTrophyProps) {
isProcessing,
msUsername,
openHelpModal,
pageContext: {
challengeMeta: { nextChallengePath, prevChallengePath }
},
t
} = props;
@@ -156,11 +153,7 @@ function MsTrophy(props: MsTrophyProps) {
)} - ${title}`;
return (
<Hotkeys
containerRef={container}
nextChallengePath={nextChallengePath}
prevChallengePath={prevChallengePath}
>
<Hotkeys containerRef={container}>
<LearnLayout>
<Helmet
title={`${blockNameTitle} | ${t('learn.learn')} | freeCodeCamp.org`}
@@ -151,9 +151,6 @@ const ShowBackEnd = (props: BackEndProps) => {
},
isChallengeCompleted,
output,
pageContext: {
challengeMeta: { nextChallengePath, prevChallengePath }
},
t,
tests,
updateSolutionFormValues
@@ -164,11 +161,7 @@ const ShowBackEnd = (props: BackEndProps) => {
)} - ${title}`;
return (
<Hotkeys
containerRef={container}
nextChallengePath={nextChallengePath}
prevChallengePath={prevChallengePath}
>
<Hotkeys containerRef={container}>
<LearnLayout>
<Helmet
title={`${blockNameTitle} | ${t('learn.learn')} | freeCodeCamp.org`}
@@ -122,9 +122,6 @@ const ShowFrontEndProject = (props: ProjectProps) => {
}
},
isChallengeCompleted,
pageContext: {
challengeMeta: { nextChallengePath, prevChallengePath }
},
t,
updateSolutionFormValues
} = props;
@@ -134,11 +131,7 @@ const ShowFrontEndProject = (props: ProjectProps) => {
)} - ${title}`;
return (
<Hotkeys
containerRef={container}
nextChallengePath={nextChallengePath}
prevChallengePath={prevChallengePath}
>
<Hotkeys containerRef={container}>
<LearnLayout>
<Helmet
title={`${blockNameTitle} | ${t('learn.learn')} | freeCodeCamp.org`}
@@ -114,7 +114,6 @@ const ShowQuiz = ({
const { t } = useTranslation();
const curLocation = useLocation();
const { nextChallengePath, prevChallengePath } = challengeMeta;
const container = useRef<HTMLElement | null>(null);
// Campers are not allowed to change their answers once the quiz is submitted.
@@ -282,8 +281,6 @@ const ShowQuiz = ({
<Hotkeys
executeChallenge={!isPassed ? handleFinishQuiz : handleSubmitAndGo}
containerRef={container}
nextChallengePath={nextChallengePath}
prevChallengePath={prevChallengePath}
>
<LearnLayout>
<Helmet