Skip to content

Commit 7cb93ac

Browse files
committed
clean up community page types
1 parent 3ff9078 commit 7cb93ac

File tree

4 files changed

+416
-130
lines changed

4 files changed

+416
-130
lines changed

packages/gatsby-theme/src/components/community/TutorialListing.tsx

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,24 @@ import UpvoteMutation from './UpvoteMutation';
77
import BookmarkMutation from './BookmarkMutation';
88
import ProgressBanner from './ProgressBanner';
99
import { getTutorialbyGatsbyID } from '../../utils/queries';
10+
import { GetTutorialbyGatsbyIdQuery, Mdx } from '../../graphqlTypes';
1011

1112
type TutorialListingProps = {
12-
tutorial: Tutorial;
13-
};
14-
15-
type Tutorial = {
16-
id: string;
17-
fileAbsolutePath: string;
18-
frontmatter: FrontMatter;
19-
};
20-
21-
type FrontMatter = {
22-
id: string;
23-
tutorialTitle: string;
24-
description: string;
13+
tutorial: Mdx;
2514
};
2615

2716
const TutorialListing: React.FunctionComponent<TutorialListingProps> = ({
2817
tutorial,
2918
}) => {
30-
const gatsbyID = tutorial.frontmatter.id;
31-
let tutorialPath = getTutorialOverviewSlug(tutorial.fileAbsolutePath);
19+
const gatsbyID = tutorial!.frontmatter!.id;
20+
let tutorialPath = getTutorialOverviewSlug(tutorial!.fileAbsolutePath);
3221
return (
33-
<Query query={getTutorialbyGatsbyID} variables={{ gatsbyID: gatsbyID }}>
22+
<Query<GetTutorialbyGatsbyIdQuery>
23+
query={getTutorialbyGatsbyID}
24+
variables={{ gatsbyID: gatsbyID }}
25+
>
3426
{({ data }) => {
27+
const gatsbyTutorial = data!.getTutorialbyGatsbyID;
3528
return (
3629
<Card
3730
width={[1]}
@@ -43,20 +36,19 @@ const TutorialListing: React.FunctionComponent<TutorialListingProps> = ({
4336
>
4437
<Flex alignItems="center" justifyContent="center">
4538
<Box width={1 / 12}>
46-
{data.getTutorialbyGatsbyID && (
39+
{gatsbyTutorial && (
4740
<div>
48-
<UpvoteMutation tutorial={data.getTutorialbyGatsbyID} />
49-
<BookmarkMutation tutorial={data.getTutorialbyGatsbyID} />
50-
<ProgressBanner tutorial={data.getTutorialbyGatsbyID} />
41+
<UpvoteMutation tutorial={gatsbyTutorial} />
42+
<BookmarkMutation tutorial={gatsbyTutorial} />
43+
<ProgressBanner tutorial={gatsbyTutorial} />
5144
</div>
5245
)}
5346
</Box>
54-
5547
<Box width={11 / 12}>
5648
<Link to={tutorialPath}>
57-
<Heading>{tutorial.frontmatter.tutorialTitle}</Heading>
49+
<Heading>{tutorial!.frontmatter!.tutorialTitle}</Heading>
5850
</Link>
59-
<Text>{tutorial.frontmatter.description}</Text>
51+
<Text>{tutorial!.frontmatter!.description}</Text>
6052
</Box>
6153
</Flex>
6254
</Card>

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ const TutorialLayout: React.FunctionComponent<TutorialLayoutProps> = ({
2222
}
2323

2424
//title of the chapter
25-
const { pageTitle } = optionalChaining(() => data.mdx.frontmatter);
25+
const { pageTitle } = optionalChaining(() => data!.mdx!.frontmatter);
2626
//title of the tutorial
2727
const tutorialTitle = optionalChaining(
28-
() => data.tutorialTitle.frontmatter.tutorialTitle,
28+
() => data!.tutorialTitle!.frontmatter!.tutorialTitle,
2929
);
3030
//gatsbyID to fetch user information about tutorial
31-
const gatsbyID = optionalChaining(() => data.tutorialTitle.frontmatter.id);
31+
const gatsbyID = optionalChaining(() => data!.tutorialTitle!.frontmatter!.id);
3232
//all chapters in this tutorial
3333
const chapters = optionalChaining(() =>
34-
data.pageTitles.edges.map(a => {
34+
data!.pageTitles!.edges!.map(a => {
3535
return {
36-
chapterTitle: optionalChaining(() => a.node.frontmatter.pageTitle),
36+
chapterTitle: optionalChaining(() => a!.node!.frontmatter!.pageTitle),
3737
chapterPath: getTutorialSlug(
3838
optionalChaining(() => a.node.fileAbsolutePath),
3939
),
@@ -42,7 +42,6 @@ const TutorialLayout: React.FunctionComponent<TutorialLayoutProps> = ({
4242
);
4343

4444
const { location } = props;
45-
4645
//all titles of chapters in this tutorial
4746
const chapterTitles = chapters.map(chapter => chapter.chapterTitle);
4847
//the number of this current chapter

0 commit comments

Comments
 (0)