Skip to content

Commit

Permalink
refactor(client): get next/prev paths directly from redux (freeCodeCa…
Browse files Browse the repository at this point in the history
  • Loading branch information
ojeytonwilliams authored Dec 7, 2024
1 parent c407c4a commit f9a8f08
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 54 deletions.
4 changes: 1 addition & 3 deletions client/src/templates/Challenges/classic/show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ function ShowClassic({
},
pageContext: {
challengeMeta,
challengeMeta: { isFirstStep, nextChallengePath, prevChallengePath },
challengeMeta: { isFirstStep, nextChallengePath },
projectPreview: { challengeData }
},
createFiles,
Expand Down Expand Up @@ -445,8 +445,6 @@ function ShowClassic({
executeChallenge={executeChallenge}
containerRef={containerRef}
instructionsPanelRef={instructionsPanelRef}
nextChallengePath={nextChallengePath}
prevChallengePath={prevChallengePath}
usesMultifileEditor={usesMultifileEditor}
editorRef={editorRef}
>
Expand Down
9 changes: 1 addition & 8 deletions client/src/templates/Challenges/codeally/show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,6 @@ function ShowCodeAlly(props: ShowCodeAllyProps) {
},
isChallengeCompleted,
isSignedIn,
pageContext: {
challengeMeta: { nextChallengePath, prevChallengePath }
},
partiallyCompletedChallenges,
t,
updateSolutionFormValues
Expand Down Expand Up @@ -260,11 +257,7 @@ function ShowCodeAlly(props: ShowCodeAllyProps) {
};

return (
<Hotkeys
containerRef={container}
nextChallengePath={nextChallengePath}
prevChallengePath={prevChallengePath}
>
<Hotkeys containerRef={container}>
<LearnLayout>
<Helmet title={windowTitle} />
<Container>
Expand Down
11 changes: 8 additions & 3 deletions client/src/templates/Challenges/components/hotkeys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -20,6 +20,7 @@ import {
import {
canFocusEditorSelector,
challengeFilesSelector,
challengeMetaSelector,
challengeTestsSelector,
isHelpModalOpenSelector,
isProjectPreviewModalOpenSelector,
Expand All @@ -39,6 +40,7 @@ const mapStateToProps = createSelector(
challengeFilesSelector,
challengeTestsSelector,
userSelector,
challengeMetaSelector,
(
isHelpModalOpen: boolean,
isResetModalOpen: boolean,
Expand All @@ -47,7 +49,8 @@ const mapStateToProps = createSelector(
canFocusEditor: boolean,
challengeFiles: ChallengeFiles,
tests: Test[],
user: User
user: User,
{ nextChallengePath, prevChallengePath }: ChallengeMeta
) => ({
isHelpModalOpen,
isResetModalOpen,
Expand All @@ -56,7 +59,9 @@ const mapStateToProps = createSelector(
canFocusEditor,
challengeFiles,
tests,
user
user,
nextChallengePath,
prevChallengePath
})
);

Expand Down
9 changes: 1 addition & 8 deletions client/src/templates/Challenges/exam/show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ function ShowExam(props: ShowExamProps) {
isChallengeCompleted,
openExitExamModal,
openFinishExamModal,
pageContext: {
challengeMeta: { nextChallengePath, prevChallengePath }
},
t
} = props;

Expand Down Expand Up @@ -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>
Expand Down
2 changes: 0 additions & 2 deletions client/src/templates/Challenges/fill-in-the-blank/show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ const ShowFillInTheBlank = ({
<Hotkeys
executeChallenge={() => handleSubmit()}
containerRef={container}
nextChallengePath={challengeMeta.nextChallengePath}
prevChallengePath={challengeMeta.prevChallengePath}
playScene={() => handlePlayScene(true)}
>
<LearnLayout>
Expand Down
3 changes: 0 additions & 3 deletions client/src/templates/Challenges/generic/show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ const ShowGeneric = ({
isChallengeCompleted
}: ShowQuizProps) => {
const { t } = useTranslation();
const { nextChallengePath, prevChallengePath } = challengeMeta;
const container = useRef<HTMLElement | null>(null);

const blockNameTitle = `${t(
Expand Down Expand Up @@ -176,8 +175,6 @@ const ShowGeneric = ({
<Hotkeys
executeChallenge={handleSubmit}
containerRef={container}
nextChallengePath={nextChallengePath}
prevChallengePath={prevChallengePath}
playScene={scene ? () => setIsScenePlaying(true) : undefined}
>
<LearnLayout>
Expand Down
9 changes: 1 addition & 8 deletions client/src/templates/Challenges/ms-trophy/show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ function MsTrophy(props: MsTrophyProps) {
isProcessing,
msUsername,
openHelpModal,
pageContext: {
challengeMeta: { nextChallengePath, prevChallengePath }
},
t
} = props;

Expand All @@ -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`}
Expand Down
9 changes: 1 addition & 8 deletions client/src/templates/Challenges/projects/backend/show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ const ShowBackEnd = (props: BackEndProps) => {
},
isChallengeCompleted,
output,
pageContext: {
challengeMeta: { nextChallengePath, prevChallengePath }
},
t,
tests,
updateSolutionFormValues
Expand All @@ -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`}
Expand Down
9 changes: 1 addition & 8 deletions client/src/templates/Challenges/projects/frontend/show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ const ShowFrontEndProject = (props: ProjectProps) => {
}
},
isChallengeCompleted,
pageContext: {
challengeMeta: { nextChallengePath, prevChallengePath }
},
t,
updateSolutionFormValues
} = props;
Expand All @@ -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`}
Expand Down
3 changes: 0 additions & 3 deletions client/src/templates/Challenges/quiz/show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -282,8 +281,6 @@ const ShowQuiz = ({
<Hotkeys
executeChallenge={!isPassed ? handleFinishQuiz : handleSubmitAndGo}
containerRef={container}
nextChallengePath={nextChallengePath}
prevChallengePath={prevChallengePath}
>
<LearnLayout>
<Helmet
Expand Down

0 comments on commit f9a8f08

Please sign in to comment.