From f2462cedb696fe5327febdb460e8d2487de41a7c Mon Sep 17 00:00:00 2001 From: moT01 Date: Fri, 1 Mar 2019 17:57:02 -0600 Subject: [PATCH] feat/add-prev-next-btns-to-lessons redirect to learn instead of home --- .../src/templates/Challenges/backend/Show.js | 15 ++++++- .../src/templates/Challenges/classic/Show.js | 13 ++++-- .../Challenges/components/Challenge-Title.js | 42 ++++++++++++++++--- .../Challenges/components/Side-Panel.js | 17 +++++++- .../Challenges/components/challenge-title.css | 17 ++++++++ .../src/templates/Challenges/project/Show.js | 7 ++++ .../Challenges/project/Side-Panel.js | 24 ++++++++++- .../src/templates/Challenges/redux/index.js | 1 + client/utils/gatsby/challengePageCreator.js | 9 +++- 9 files changed, 131 insertions(+), 14 deletions(-) create mode 100644 client/src/templates/Challenges/components/challenge-title.css diff --git a/client/src/templates/Challenges/backend/Show.js b/client/src/templates/Challenges/backend/Show.js index 743fae029e..2c1c4328aa 100644 --- a/client/src/templates/Challenges/backend/Show.js +++ b/client/src/templates/Challenges/backend/Show.js @@ -49,6 +49,9 @@ const propTypes = { id: PropTypes.string, initTests: PropTypes.func.isRequired, output: PropTypes.string, + pageContext: PropTypes.shape({ + challengeMeta: PropTypes.object + }), tests: PropTypes.array, title: PropTypes.string, updateChallengeMeta: PropTypes.func.isRequired, @@ -156,6 +159,9 @@ export class BackEnd extends Component { } }, output, + pageContext: { + challengeMeta: { introPath, nextChallengePath, prevChallengePath } + }, tests, submitting, executeChallenge @@ -172,7 +178,14 @@ export class BackEnd extends Component { - {blockNameTitle} + + {blockNameTitle} + - {children || 'Happy Coding!'} - {icon} - +
+ {showPrevNextBtns ? ( + + ) : null} +

+ {children || 'Happy Coding!'} + {icon} +

+ {showPrevNextBtns ? ( + + ) : null} +
); } diff --git a/client/src/templates/Challenges/components/Side-Panel.js b/client/src/templates/Challenges/components/Side-Panel.js index 1e7684ca1e..1adfca2ee6 100644 --- a/client/src/templates/Challenges/components/Side-Panel.js +++ b/client/src/templates/Challenges/components/Side-Panel.js @@ -35,7 +35,11 @@ const propTypes = { guideUrl: PropTypes.string, initConsole: PropTypes.func.isRequired, instructions: PropTypes.string, + introPath: PropTypes.string, + nextChallengePath: PropTypes.string, + prevChallengePath: PropTypes.string, section: PropTypes.string, + showPrevNextBtns: PropTypes.bool, showToolPanel: PropTypes.bool, tests: PropTypes.arrayOf(PropTypes.object), title: PropTypes.string, @@ -64,9 +68,13 @@ export class SidePanel extends Component { title, description, instructions, + introPath, guideUrl, + nextChallengePath, + prevChallengePath, tests, section, + showPrevNextBtns, showToolPanel, videoUrl } = this.props; @@ -74,7 +82,14 @@ export class SidePanel extends Component {
- {title} + + {title} + Button { + flex-grow: 1; +} \ No newline at end of file diff --git a/client/src/templates/Challenges/project/Show.js b/client/src/templates/Challenges/project/Show.js index 54596c4ef1..5eb01080b7 100644 --- a/client/src/templates/Challenges/project/Show.js +++ b/client/src/templates/Challenges/project/Show.js @@ -100,6 +100,9 @@ export class Project extends Component { } }, openCompletionModal, + pageContext: { + challengeMeta: { introPath, nextChallengePath, prevChallengePath } + }, updateProjectFormValues } = this.props; const isFrontEnd = challengeType === frontEndProject; @@ -113,6 +116,10 @@ export class Project extends Component { className='full-height' description={description} guideUrl={guideUrl} + introPath={introPath} + nextChallengePath={nextChallengePath} + prevChallengePath={prevChallengePath} + showPrevNextBtns={true} title={blockNameTitle} /> - {title} + + {title} +
); diff --git a/client/src/templates/Challenges/redux/index.js b/client/src/templates/Challenges/redux/index.js index 59308775a0..8f9b618c08 100644 --- a/client/src/templates/Challenges/redux/index.js +++ b/client/src/templates/Challenges/redux/index.js @@ -25,6 +25,7 @@ const initialState = { challengeMeta: { id: '', nextChallengePath: '/', + prevChallengePath: '/', introPath: '', challengeType: -1 }, diff --git a/client/utils/gatsby/challengePageCreator.js b/client/utils/gatsby/challengePageCreator.js index 203e68feb2..91a981ec95 100644 --- a/client/utils/gatsby/challengePageCreator.js +++ b/client/utils/gatsby/challengePageCreator.js @@ -34,8 +34,14 @@ const views = { const getNextChallengePath = (node, index, nodeArray) => { const next = nodeArray[index + 1]; - return next ? next.node.fields.slug : '/'; + return next ? next.node.fields.slug : '/learn'; }; + +const getPrevChallengePath = (node, index, nodeArray) => { + const prev = nodeArray[index - 1]; + return prev ? prev.node.fields.slug : '/learn'; +}; + const getTemplateComponent = challengeType => views[viewTypes[challengeType]]; const getIntroIfRequired = (node, index, nodeArray) => { @@ -74,6 +80,7 @@ exports.createChallengePages = createPage => ({ node }, index, thisArray) => { template, required, nextChallengePath: getNextChallengePath(node, index, thisArray), + prevChallengePath: getPrevChallengePath(node, index, thisArray), id }, slug