Skip to content

Commit bb9303d

Browse files
committed
link to the user's current chapter on the tutorial page
1 parent c920aca commit bb9303d

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

packages/gatsby-theme/src/components/templates/TutorialOverview.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ interface PageTemplateProps {
1616

1717
const PageTemplate: React.FunctionComponent<PageTemplateProps> = ({ data }) => {
1818
let gatsbyID = optionalChaining(() => data.overview.frontmatter.id);
19-
// TO DO change this component so it links to the chapter the user is currently on
20-
let firstChapterPath = getTutorialSlug(
21-
optionalChaining(() => data.allMdx.edges[0].node.fileAbsolutePath),
19+
20+
// This is so that the start button can link to the user's current path
21+
// TO DO find a better way to pass in the which chapter the user is currently on
22+
const chapterPaths = optionalChaining(() =>
23+
data.allMdx.edges.map(a =>
24+
getTutorialSlug(optionalChaining(() => a.node.fileAbsolutePath)),
25+
),
2226
);
27+
2328
return (
2429
<Layout>
2530
<Content>
@@ -33,7 +38,10 @@ const PageTemplate: React.FunctionComponent<PageTemplateProps> = ({ data }) => {
3338
/>
3439
</Box>
3540
<Box width={1 / 4} m={3}>
36-
<AuthorsProgressBox gatsbyID={gatsbyID} path={firstChapterPath} />
41+
<AuthorsProgressBox
42+
gatsbyID={gatsbyID}
43+
chapterPaths={chapterPaths}
44+
/>
3745
</Box>
3846
</Flex>
3947
<div>

packages/gatsby-theme/src/components/tutorial/AuthorsProgressBox.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,37 @@ import {
1212
import { Flex, Box } from '../shared/base';
1313
import { optionalChaining, percent } from '../../utils/helpers';
1414

15-
const AuthorsProgressBox = ({ gatsbyID, path }) => (
15+
const AuthorsProgressBox = ({ gatsbyID, chapterPaths }) => (
1616
<Query query={getTutorialbyGatsbyID} variables={{ gatsbyID: gatsbyID }}>
1717
{({ data }) => {
1818
let buttonText = 'Start Tutorial';
1919
let percentage = 0;
20-
21-
if (
20+
let currentChapter =
2221
optionalChaining(
2322
() => data.getTutorialbyGatsbyID.viewerUserTutorial.currentChapter,
24-
)
25-
) {
23+
) || 0;
24+
//This link you to the next chapter you have not done
25+
let currentChapterPath = chapterPaths[0];
26+
if (currentChapter) {
2627
percentage = percent(
2728
data.getTutorialbyGatsbyID.numberofChapters,
2829
data.getTutorialbyGatsbyID.viewerUserTutorial.currentChapter,
2930
);
3031
buttonText = 'Continue Tutorial';
32+
3133
if (percentage === 100) {
3234
buttonText = 'Take Again';
35+
} else {
36+
//This link you to the next chapter you have not done. Since this is
37+
//an array you don't need to add 1
38+
// if you have already completed the tutorial you are still sent
39+
//to the first chapter
40+
currentChapterPath = chapterPaths[currentChapter];
3341
}
3442
}
3543
return (
3644
<div>
37-
<a href={path}>
45+
<a href={currentChapterPath}>
3846
<TutorialButton>{buttonText}</TutorialButton>
3947
</a>
4048
{!!percentage && (

0 commit comments

Comments
 (0)