Skip to content

Commit 74e6dbb

Browse files
committed
get current progress on community tutorial page
1 parent e9e639d commit 74e6dbb

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

oss

Submodule oss updated from d629d35 to a977db4
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;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface FillerProps {
4141
percentage: number;
4242
}
4343

44-
const Filler = styled('div')<FillerProps>`
44+
const Filler = styled.div<FillerProps>`
4545
background: ${props => props.theme.colors.primary};
4646
height: 100%;
4747
border-radius: inherit;

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Query } from 'react-apollo';
66
import gql from 'graphql-tag';
77
import UpvoteMutation from './UpvoteMutation';
88
import BookmarkMutation from './BookmarkMutation';
9+
import Percentage from './Percentage';
910

1011
type TutorialListingProps = {
1112
tutorial: Tutorial;
@@ -27,6 +28,7 @@ const TutorialListing: React.FunctionComponent<TutorialListingProps> = ({
2728
tutorial,
2829
}) => {
2930
const gatsbyID = tutorial.frontmatter.id;
31+
let tutorialPath = getTutorialOverviewSlug(tutorial.fileAbsolutePath);
3032
return (
3133
<Query
3234
query={gql`
@@ -35,11 +37,13 @@ const TutorialListing: React.FunctionComponent<TutorialListingProps> = ({
3537
id
3638
name
3739
upvotes
40+
numberofChapters
3841
numberOfStudents
3942
viewerUserTutorial {
4043
id
4144
upvoted
4245
bookmarked
46+
currentChapter
4347
}
4448
}
4549
}
@@ -52,15 +56,16 @@ const TutorialListing: React.FunctionComponent<TutorialListingProps> = ({
5256
<Flex alignItems="center" justifyContent="center">
5357
<Box width={1 / 12}>
5458
{data.getTutorialbyGatsbyID && (
55-
<UpvoteMutation tutorial={data.getTutorialbyGatsbyID} />
56-
)}
57-
{data.getTutorialbyGatsbyID && (
58-
<BookmarkMutation tutorial={data.getTutorialbyGatsbyID} />
59+
<div>
60+
<UpvoteMutation tutorial={data.getTutorialbyGatsbyID} />
61+
<BookmarkMutation tutorial={data.getTutorialbyGatsbyID} />
62+
<Percentage tutorial={data.getTutorialbyGatsbyID} />
63+
</div>
5964
)}
6065
</Box>
6166

6267
<Box width={11 / 12}>
63-
<Link to={getTutorialOverviewSlug(tutorial.fileAbsolutePath)}>
68+
<Link to={tutorialPath}>
6469
<Heading>{tutorial.frontmatter.tutorialTitle}</Heading>
6570
</Link>
6671
<Text>{tutorial.frontmatter.description}</Text>

0 commit comments

Comments
 (0)