Skip to content

Commit e07cb95

Browse files
committed
refactor TutorialListing, add type
1 parent 9fa8a89 commit e07cb95

File tree

2 files changed

+50
-24
lines changed

2 files changed

+50
-24
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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
26+
width={[1]}
27+
p={4}
28+
my={4}
29+
borderRadius={8}
30+
boxShadow="small"
31+
key={tutorial.id}
32+
>
33+
<Link to={getTutorialOverviewSlug(tutorial.fileAbsolutePath)}>
34+
<Heading>{tutorial.frontmatter.tutorialTitle}</Heading>
35+
</Link>
36+
<Text>{tutorial.frontmatter.description}</Text>
37+
</Card>
38+
);
39+
};
40+
41+
export default TutorialListing;

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

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,20 @@
11
import * as React from 'react';
22
import Layout from '../components/layout';
3-
import { Content } from '../shared/styledHelpers';
3+
import { Content } from '../components/shared/styledHelpers';
44
import { graphql } from 'gatsby';
5-
import { Heading, Text, Card } from '../components/shared/base';
6-
import { getTutorialSlug } from '../utils/getTutorialSlug';
7-
import { Link } from 'gatsby';
5+
import TutorialListing from '../components/TutorialListing';
6+
import { Heading } from '../components/shared/base';
87

98
const Community = data => {
10-
console.log(data);
11-
console.log(data.data.tutorials.edges);
129
const tutorials = data.data.tutorials.edges;
1310
return (
1411
<Layout>
15-
<Heading> Community Tutorials </Heading>
16-
{tutorials.map(tutorial => {
17-
return (
18-
<Card
19-
width={[1]}
20-
p={4}
21-
my={4}
22-
borderRadius={8}
23-
boxShadow="small"
24-
key={tutorial.node.id}
25-
>
26-
<Link to={getTutorialSlug(tutorial.node.fileAbsolutePath)}>
27-
<Heading>{tutorial.node.frontmatter.tutorialTitle}</Heading>
28-
</Link>
29-
<Text>{tutorial.node.frontmatter.description}</Text>
30-
</Card>
31-
);
32-
})}
12+
<Content>
13+
<Heading> Community Tutorials </Heading>
14+
{tutorials.map(tutorial => {
15+
return <TutorialListing tutorial={tutorial.node} />;
16+
})}
17+
</Content>
3318
</Layout>
3419
);
3520
};

0 commit comments

Comments
 (0)