File tree Expand file tree Collapse file tree 2 files changed +26
-10
lines changed
packages/gatsby-theme/src/components Expand file tree Collapse file tree 2 files changed +26
-10
lines changed Original file line number Diff line number Diff line change @@ -16,10 +16,15 @@ interface PageTemplateProps {
16
16
17
17
const PageTemplate : React . FunctionComponent < PageTemplateProps > = ( { data } ) => {
18
18
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
+ ) ,
22
26
) ;
27
+
23
28
return (
24
29
< Layout >
25
30
< Content >
@@ -33,7 +38,10 @@ const PageTemplate: React.FunctionComponent<PageTemplateProps> = ({ data }) => {
33
38
/>
34
39
</ Box >
35
40
< Box width = { 1 / 4 } m = { 3 } >
36
- < AuthorsProgressBox gatsbyID = { gatsbyID } path = { firstChapterPath } />
41
+ < AuthorsProgressBox
42
+ gatsbyID = { gatsbyID }
43
+ chapterPaths = { chapterPaths }
44
+ />
37
45
</ Box >
38
46
</ Flex >
39
47
< div >
Original file line number Diff line number Diff line change @@ -12,29 +12,37 @@ import {
12
12
import { Flex , Box } from '../shared/base' ;
13
13
import { optionalChaining , percent } from '../../utils/helpers' ;
14
14
15
- const AuthorsProgressBox = ( { gatsbyID, path } ) => (
15
+ const AuthorsProgressBox = ( { gatsbyID, chapterPaths } ) => (
16
16
< Query query = { getTutorialbyGatsbyID } variables = { { gatsbyID : gatsbyID } } >
17
17
{ ( { data } ) => {
18
18
let buttonText = 'Start Tutorial' ;
19
19
let percentage = 0 ;
20
-
21
- if (
20
+ let currentChapter =
22
21
optionalChaining (
23
22
( ) => 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 ) {
26
27
percentage = percent (
27
28
data . getTutorialbyGatsbyID . numberofChapters ,
28
29
data . getTutorialbyGatsbyID . viewerUserTutorial . currentChapter ,
29
30
) ;
30
31
buttonText = 'Continue Tutorial' ;
32
+
31
33
if ( percentage === 100 ) {
32
34
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 ] ;
33
41
}
34
42
}
35
43
return (
36
44
< div >
37
- < a href = { path } >
45
+ < a href = { currentChapterPath } >
38
46
< TutorialButton > { buttonText } </ TutorialButton >
39
47
</ a >
40
48
{ ! ! percentage && (
You can’t perform that action at this time.
0 commit comments