Skip to content

Commit e2402c6

Browse files
authored
Merge pull request #20 from howtographql/community-tutorial-listing-page
Community tutorial listing page
2 parents f625543 + 9c0a1a6 commit e2402c6

File tree

7 files changed

+132
-18
lines changed

7 files changed

+132
-18
lines changed

packages/gatsby-theme/src/components/Chapter.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
11
import React from 'react';
2+
import { getTutorialSlug } from '../utils/getTutorialSlug';
3+
import { Link } from 'gatsby';
24
import { Heading, Text, Flex, Card } from './shared/base';
35

46
type ChapterProps = {
57
num: string | number;
6-
title: string | null;
7-
description: string | null;
8+
tutorial: Tutorial;
9+
};
10+
11+
type Tutorial = {
12+
id: string;
13+
fileAbsolutePath: string;
14+
frontmatter: FrontMatter;
815
};
916

17+
type FrontMatter = {
18+
pageTitle: string | null;
19+
description: string | null;
20+
}
21+
1022
const Chapter: React.FunctionComponent<ChapterProps> = ({
11-
num,
12-
title,
13-
description,
23+
num, tutorial
1424
}) => {
1525
return (
1626
<Card width={[1]} p={4} my={4} borderRadius={8} boxShadow="small">
1727
<Flex alignItems="center">
1828
<Heading p={4}>{num}</Heading>
1929
<div>
20-
<Heading as="h2">{title}</Heading>
21-
<Text>{description}</Text>
30+
<Link to={getTutorialSlug(tutorial.fileAbsolutePath)}>
31+
<Heading as="h2">{tutorial.frontmatter.pageTitle}</Heading>
32+
</Link>
33+
<Text>{tutorial.frontmatter.description}</Text>
34+
2235
</div>
2336
</Flex>
2437
</Card>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import * as React from 'react';
2+
import { Heading, Text, Card } from './shared/base';
3+
import { getTutorialOverviewSlug } from '../utils/getTutorialSlug';
4+
import { Link } from 'gatsby';
5+
6+
type TutorialListingProps = {
7+
tutorial: Tutorial;
8+
};
9+
10+
type Tutorial = {
11+
id: string;
12+
fileAbsolutePath: string;
13+
frontmatter: FrontMatter;
14+
};
15+
16+
type FrontMatter = {
17+
tutorialTitle: string;
18+
description: string;
19+
};
20+
21+
const TutorialListing: React.FunctionComponent<TutorialListingProps> = ({
22+
tutorial,
23+
}) => {
24+
return (
25+
<Card width={[1]} p={4} my={4} borderRadius={8} boxShadow="small">
26+
<Link to={getTutorialOverviewSlug(tutorial.fileAbsolutePath)}>
27+
<Heading>{tutorial.frontmatter.tutorialTitle}</Heading>
28+
</Link>
29+
<Text>{tutorial.frontmatter.description}</Text>
30+
</Card>
31+
);
32+
};
33+
34+
export default TutorialListing;

packages/gatsby-theme/src/components/shared/Header.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ const Nav = withTheme(
5151
</Container>
5252
<Container justifyContent="center">
5353
<NavLink to="/fundamentals">Fundamentals</NavLink>
54-
<NavLink to="/guides">Guides</NavLink>
55-
<NavLink to="/community">Community</NavLink>
54+
<NavLink to="/courses">FullStack Course</NavLink>
55+
<NavLink to="/community">Community Tutorials</NavLink>
5656
<NavLink to="/components">Components</NavLink>
5757
</Container>
5858
<Container justifyContent="flex-end">

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ const PageTemplate: React.FunctionComponent<PageTemplateProps> = ({ data }) => {
4848
<div>
4949
<Chapter
5050
num={num < 10 ? `0${num}` : num}
51-
title={mdx.node.frontmatter!.pageTitle}
52-
description={mdx.node.frontmatter!.description}
51+
tutorial = {mdx.node}
5352
/>
5453
</div>
5554
);
@@ -73,6 +72,7 @@ export const query = graphql`
7372
edges {
7473
node {
7574
id
75+
fileAbsolutePath
7676
frontmatter {
7777
pageTitle
7878
description
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import * as React from 'react';
2+
import Layout from '../components/layout';
3+
import { Content } from '../components/shared/styledHelpers';
4+
import { graphql } from 'gatsby';
5+
import TutorialListing from '../components/TutorialListing';
6+
import { Heading } from '../components/shared/base';
7+
8+
const Community = data => {
9+
const tutorials = data.data.tutorials.edges;
10+
return (
11+
<Layout>
12+
<Content>
13+
<Heading> Community Tutorials </Heading>
14+
{tutorials.map(tutorial => {
15+
return (
16+
<div key={tutorial.node.id}>
17+
<TutorialListing tutorial={tutorial.node} />
18+
</div>
19+
);
20+
})}
21+
</Content>
22+
</Layout>
23+
);
24+
};
25+
26+
export const query = graphql`
27+
query CommunityTutorialQuery {
28+
tutorials: allMdx(
29+
filter: {
30+
frontmatter: { tutorialTitle: { ne: null } }
31+
fileAbsolutePath: { regex: "/community/" }
32+
}
33+
) {
34+
edges {
35+
node {
36+
id
37+
fileAbsolutePath
38+
frontmatter {
39+
tutorialTitle
40+
description
41+
}
42+
}
43+
}
44+
}
45+
}
46+
`;
47+
48+
export default Community;

packages/gatsby-theme/src/pages/components.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Link } from "gatsby";
2-
import * as React from "react";
3-
import Layout from "../components/layout";
1+
import { Link } from 'gatsby';
2+
import * as React from 'react';
3+
import Layout from '../components/layout';
44
import {
55
Box,
66
Flex,
@@ -9,10 +9,10 @@ import {
99
Button,
1010
Image,
1111
Card,
12-
Link as BaseLink
13-
} from "../components/shared/base";
12+
Link as BaseLink,
13+
} from '../components/shared/base';
1414

15-
const SecondPage = () => (
15+
const Components = () => (
1616
<Layout>
1717
<h3>Check out our rebass components!</h3>
1818

@@ -65,4 +65,4 @@ const SecondPage = () => (
6565
</Layout>
6666
);
6767

68-
export default SecondPage;
68+
export default Components;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as React from 'react';
2+
import Layout from '../components/layout';
3+
import { Content } from '../components/shared/styledHelpers';
4+
import { Heading, Text } from '../components/shared/base';
5+
6+
const courses = () => {
7+
return (
8+
<Layout>
9+
<Content>
10+
<Heading> Fullstack Course </Heading>
11+
<Text>A general introduction to GraphQL for frontend and backend developers.</Text>
12+
<Text> Read this tutorial to learn about GraphQL's basic concepts and prepare
13+
yourself for a hands-on beginner tutorial.</Text>
14+
</Content>
15+
</Layout>
16+
);
17+
};
18+
19+
export default courses;

0 commit comments

Comments
 (0)