Skip to content

Commit c920aca

Browse files
committed
link to the chapers in the sidebar of a tutorial
1 parent 21cdbce commit c920aca

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ const TutorialLayout: React.FunctionComponent<TutorialLayoutProps> = ({
3434
data.pageTitles.edges.map(a => {
3535
return {
3636
chapterTitle: optionalChaining(() => a.node.frontmatter.pageTitle),
37-
chapterPath: optionalChaining(() => a.node.fileAbsolutePath),
37+
chapterPath: getTutorialSlug(
38+
optionalChaining(() => a.node.fileAbsolutePath),
39+
),
3840
};
3941
}),
4042
);
@@ -45,14 +47,15 @@ const TutorialLayout: React.FunctionComponent<TutorialLayoutProps> = ({
4547
const chapterTitles = chapters.map(chapter => chapter.chapterTitle);
4648
//the number of this current chapter
4749
const currentChapterIndex = chapterTitles.indexOf(pageTitle);
50+
//get the next chapter path
4851
const findNextChapterPath = () => {
4952
if (currentChapterIndex + 1 === chapters.length) {
5053
return null;
5154
} else {
52-
return getTutorialSlug(chapters[currentChapterIndex + 1].chapterPath);
55+
return chapters[currentChapterIndex + 1].chapterPath;
5356
}
5457
};
55-
58+
//evaluate findNextChapterPath to get the next chapter.
5659
const nextChapterPath = findNextChapterPath();
5760

5861
return (
@@ -63,17 +66,14 @@ const TutorialLayout: React.FunctionComponent<TutorialLayoutProps> = ({
6366
<h1>{pageTitle}</h1>
6467
</Box>
6568
<Box width={1 / 8} m={2}>
66-
<TabletSidebar
67-
chapters={chapterTitles}
68-
tutorialTitle={tutorialTitle}
69-
/>
69+
<TabletSidebar chapters={chapters} tutorialTitle={tutorialTitle} />
7070
</Box>
7171
</Flex>
7272
</ShowOnTablet>
7373
<HideOnTablet>
7474
<Flex>
7575
<Box width={1 / 4} m={2}>
76-
<Sidebar chapters={chapterTitles} tutorialTitle={tutorialTitle} />
76+
<Sidebar chapters={chapters} tutorialTitle={tutorialTitle} />
7777
</Box>
7878
<Box width={3 / 4} m={2}>
7979
<h1>{pageTitle}</h1>

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ import AuthorsProgressBox from '../tutorial/AuthorsProgressBox';
88
import { Content } from '../shared/styledHelpers';
99
import { graphql } from 'gatsby';
1010
import { optionalChaining } from '../../utils/helpers';
11+
import { getTutorialSlug } from '../../utils/getTutorialSlug';
1112

1213
interface PageTemplateProps {
1314
data: TutorialOverviewQuery;
1415
}
1516

1617
const PageTemplate: React.FunctionComponent<PageTemplateProps> = ({ data }) => {
1718
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),
22+
);
1823
return (
1924
<Layout>
2025
<Content>
@@ -28,7 +33,7 @@ const PageTemplate: React.FunctionComponent<PageTemplateProps> = ({ data }) => {
2833
/>
2934
</Box>
3035
<Box width={1 / 4} m={3}>
31-
<AuthorsProgressBox gatsbyID={gatsbyID} />
36+
<AuthorsProgressBox gatsbyID={gatsbyID} path={firstChapterPath} />
3237
</Box>
3338
</Flex>
3439
<div>

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

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

15-
const AuthorsProgressBox = ({ gatsbyID }) => (
15+
const AuthorsProgressBox = ({ gatsbyID, path }) => (
1616
<Query query={getTutorialbyGatsbyID} variables={{ gatsbyID: gatsbyID }}>
1717
{({ data }) => {
1818
let buttonText = 'Start Tutorial';
@@ -34,7 +34,9 @@ const AuthorsProgressBox = ({ gatsbyID }) => (
3434
}
3535
return (
3636
<div>
37-
<TutorialButton>{buttonText}</TutorialButton>
37+
<a href={path}>
38+
<TutorialButton>{buttonText}</TutorialButton>
39+
</a>
3840
{!!percentage && (
3941
<Box m={3}>
4042
<ProgressBar percentage={percentage} />

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ export const Sidebar: React.FunctionComponent<SidebarProps> = ({
2222
</Card>
2323
<ul>
2424
{chapters.map(chapter => (
25-
<li key={chapter}>{chapter}</li>
25+
<li key={chapter.chapterTitle}>
26+
<a href={chapter.chapterPath}>{chapter.chapterTitle}</a>
27+
</li>
2628
))}
2729
</ul>
2830
<AuthorList authors={authors} />

0 commit comments

Comments
 (0)