Skip to content

Commit c271043

Browse files
committed
reorganize components into folders, move queries out of componets and into utils
1 parent 74e6dbb commit c271043

25 files changed

+276
-254
lines changed

packages/gatsby-theme/src/components/BookmarkMutation.tsx renamed to packages/gatsby-theme/src/components/community/BookmarkMutation.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
11
import * as React from 'react';
2-
import gql from 'graphql-tag';
32
import { Mutation } from 'react-apollo';
43
import { loginUser } from '../utils/auth';
54
import { BookmarkButton } from './buttons';
5+
import { BookmarkTutorial } from '../utils/queries/tutorial';
66
import { handleMutationResponse, ApiErrors } from '../utils/errorHandling';
77

88
const BookmarkMutation = ({ tutorial }) => (
99
<Mutation
10-
mutation={gql`
11-
mutation BookmarkTutorial($id: ID!) {
12-
bookmarkTutorial(tutorialId: $id) {
13-
code
14-
success
15-
userTutorial {
16-
id
17-
bookmarked
18-
}
19-
}
20-
}
21-
`}
10+
mutation={BookmarkTutorial}
2211
variables={{
2312
id: tutorial.id,
2413
}}

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

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { Heading, Text, Card, Flex, Box } from './shared/base';
33
import { getTutorialOverviewSlug } from '../utils/getTutorialSlug';
44
import { Link } from 'gatsby';
55
import { Query } from 'react-apollo';
6-
import gql from 'graphql-tag';
76
import UpvoteMutation from './UpvoteMutation';
87
import BookmarkMutation from './BookmarkMutation';
98
import Percentage from './Percentage';
9+
import { getTutorialbyGatsbyID } from '../utils/queries/tutorial';
1010

1111
type TutorialListingProps = {
1212
tutorial: Tutorial;
@@ -30,26 +30,7 @@ const TutorialListing: React.FunctionComponent<TutorialListingProps> = ({
3030
const gatsbyID = tutorial.frontmatter.id;
3131
let tutorialPath = getTutorialOverviewSlug(tutorial.fileAbsolutePath);
3232
return (
33-
<Query
34-
query={gql`
35-
query getTutorialbyGatsbyID($gatsbyID: String!) {
36-
getTutorialbyGatsbyID(gatsbyID: $gatsbyID) {
37-
id
38-
name
39-
upvotes
40-
numberofChapters
41-
numberOfStudents
42-
viewerUserTutorial {
43-
id
44-
upvoted
45-
bookmarked
46-
currentChapter
47-
}
48-
}
49-
}
50-
`}
51-
variables={{ gatsbyID: gatsbyID }}
52-
>
33+
<Query query={getTutorialbyGatsbyID} variables={{ gatsbyID: gatsbyID }}>
5334
{({ data }) => {
5435
return (
5536
<Card width={[1]} p={4} my={4} borderRadius={8} boxShadow="small">

packages/gatsby-theme/src/components/UpvoteMutation.tsx renamed to packages/gatsby-theme/src/components/community/UpvoteMutation.tsx

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,13 @@
11
import * as React from 'react';
2-
import gql from 'graphql-tag';
32
import { Mutation } from 'react-apollo';
43
import { loginUser } from '../utils/auth';
54
import { handleMutationResponse, ApiErrors } from '../utils/errorHandling';
65
import { VoteButton } from './buttons';
76
import { Heading, Flex } from './shared/base';
7+
import { UpvoteTutorial } from '../utils/queries/tutorial';
88

99
const UpvoteMutation = ({ tutorial }) => (
10-
<Mutation
11-
mutation={gql`
12-
mutation UpvoteTutorial($id: ID!) {
13-
upvoteTutorial(tutorialId: $id) {
14-
code
15-
success
16-
userTutorial {
17-
id
18-
upvoted
19-
tutorial {
20-
id
21-
upvotes
22-
}
23-
}
24-
}
25-
}
26-
`}
27-
variables={{
28-
id: tutorial.id,
29-
}}
30-
>
10+
<Mutation mutation={UpvoteTutorial} variables={{ id: tutorial.id }}>
3111
{upvote => {
3212
let active = tutorial.viewerUserTutorial.upvoted;
3313
let upvotes = tutorial.upvotes;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as React from 'react';
2+
import { Card, Flex, Image } from '../shared/base';
3+
import ProgressBar from '../shared/ProgressBar';
4+
import { TutorialButton } from '../shared/buttons';
5+
import { getTutorialOverviewSlug } from '../../utils/getTutorialSlug';
6+
7+
type CourseCardProps = {
8+
tutorialTitle: string;
9+
fileAbsolutePath: string;
10+
};
11+
12+
const CourseCard: React.FunctionComponent<CourseCardProps> = ({
13+
tutorialTitle,
14+
fileAbsolutePath,
15+
}) => {
16+
return (
17+
<Card m={[1, 1, 1]} p={[2, 2, 2]}>
18+
<Flex flexDirection="column" alignItems="center" justifyContent="center">
19+
<Image
20+
width={[0.5, 0.5, 0.5]}
21+
src="https://i.ibb.co/TcKwmwR/Icons.png"
22+
/>
23+
<h3>{tutorialTitle}</h3>
24+
<ProgressBar percentage={Math.floor(Math.random() * 100)} width={80} />
25+
<a href={getTutorialOverviewSlug(fileAbsolutePath)}>
26+
<TutorialButton>Start Tutorial</TutorialButton>
27+
</a>
28+
</Flex>
29+
</Card>
30+
);
31+
};
32+
33+
export default CourseCard;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import * as React from 'react';
2+
import { Heading, Text, Flex, Box } from '../shared/base';
3+
import CourseCard from './CourseCard';
4+
5+
type CourseSectionProps = {
6+
heading: string;
7+
body: string;
8+
data: [QueryData];
9+
};
10+
11+
type QueryData = {
12+
node: Node;
13+
};
14+
15+
type Node = {
16+
id: string;
17+
fileAbsolutePath: string;
18+
frontmatter: Frontmatter;
19+
};
20+
21+
type Frontmatter = {
22+
tutorialTitle: string;
23+
description: string;
24+
};
25+
26+
const CourseSection: React.FunctionComponent<CourseSectionProps> = ({
27+
heading,
28+
body,
29+
data,
30+
}) => {
31+
return (
32+
<Flex m={[1, 1, 1]}>
33+
<Box width={[0.2, 0.2, 0.2]}>
34+
<Heading> {heading} </Heading>
35+
<Text>{body}</Text>
36+
</Box>
37+
<Box width={[0.8, 0.8, 0.8]}>
38+
<Flex alignItems="top" justifyContent="center" flexWrap="wrap">
39+
{data.map(tutorial => (
40+
<Box width={[1, 0.8, 0.4]} key={tutorial.node.id}>
41+
<CourseCard
42+
tutorialTitle={tutorial.node.frontmatter.tutorialTitle}
43+
fileAbsolutePath={tutorial.node.fileAbsolutePath}
44+
/>
45+
</Box>
46+
))}
47+
</Flex>
48+
</Box>
49+
</Flex>
50+
);
51+
};
52+
53+
export default CourseSection;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as React from 'react';
2+
import { Text } from './shared/base';
3+
4+
const Percentage = ({ tutorial }) => {
5+
let progress = tutorial.viewerUserTutorial.currentChapter;
6+
let percentage = progress
7+
? Math.floor((progress / tutorial.numberofChapters) * 100)
8+
: 0;
9+
return (
10+
<div>
11+
{percentage ? <Text>{percentage}%</Text> : <Text> No Progress </Text>}
12+
</div>
13+
);
14+
};
15+
16+
export default Percentage;

0 commit comments

Comments
 (0)