Skip to content

Commit f65f4dc

Browse files
committed
inital set up for voting mechanism
1 parent e2402c6 commit f65f4dc

File tree

3 files changed

+55
-6
lines changed

3 files changed

+55
-6
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { ButtonProps } from './shared/base.d';
33
import { Flex, Image, Button } from './shared/base';
44

55
export const CustomButton: React.FunctionComponent<
6-
ButtonProps & { type?: 'github' | 'tutorial' | 'spectrum' | 'default' }
6+
ButtonProps & {
7+
type?: 'github' | 'tutorial' | 'spectrum' | 'vote' | 'default';
8+
}
79
> = ({ type = 'default', children, ...buttonProps }) => {
810
const { icon, bg } = customButtonTypes[type];
911

@@ -30,6 +32,7 @@ interface CustomButtonType {
3032
tutorial: ButtonType;
3133
github: ButtonType;
3234
spectrum: ButtonType;
35+
vote: ButtonType;
3336
default: ButtonType;
3437
}
3538

@@ -46,6 +49,10 @@ const customButtonTypes: CustomButtonType = {
4649
icon: 'https://i.ibb.co/gmtgnsP/Spectrum.png',
4750
bg: 'grey',
4851
},
52+
vote: {
53+
icon: 'https://i.ibb.co/b3FGXbD/Vote.png',
54+
bg: 'white',
55+
},
4956
default: {
5057
icon: '',
5158
bg: 'primary',

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
2-
import { Heading, Text, Card } from './shared/base';
2+
import { Heading, Text, Card, Flex, Box } from './shared/base';
33
import { getTutorialOverviewSlug } from '../utils/getTutorialSlug';
4+
import Upvote from './Upvote';
45
import { Link } from 'gatsby';
56

67
type TutorialListingProps = {
@@ -23,10 +24,17 @@ const TutorialListing: React.FunctionComponent<TutorialListingProps> = ({
2324
}) => {
2425
return (
2526
<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>
27+
<Flex alignItems="center" justifyContent="center">
28+
<Box width={1 / 12}>
29+
<Upvote />
30+
</Box>
31+
<Box width={11 / 12}>
32+
<Link to={getTutorialOverviewSlug(tutorial.fileAbsolutePath)}>
33+
<Heading>{tutorial.frontmatter.tutorialTitle}</Heading>
34+
</Link>
35+
<Text>{tutorial.frontmatter.description}</Text>
36+
</Box>
37+
</Flex>
3038
</Card>
3139
);
3240
};
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 { Query } from 'react-apollo';
3+
import { CurrentUserQuery } from '../graphqlTypes';
4+
import { Image, Heading, Flex } from './shared/base';
5+
import CustomButton from './CustomButton';
6+
import { optionalChaining } from '../utils/helpers';
7+
import { loginUser } from '../utils/auth';
8+
import { CURRENT_USER } from './queries/userQueries';
9+
10+
const Upvote = () => {
11+
return (
12+
<Query<CurrentUserQuery> query={CURRENT_USER}>
13+
{({ data, error, loading }) => {
14+
if (error || loading) {
15+
return null;
16+
}
17+
if (optionalChaining(() => data.viewer.user)) {
18+
return <UpvoteData event={() => console.log('upvoted!')} />;
19+
}
20+
return <UpvoteData event={() => loginUser()} />;
21+
}}
22+
</Query>
23+
);
24+
};
25+
26+
const UpvoteData = props => {
27+
return (
28+
<Flex flexDirection="column" alignItems="center" justifyContent="center">
29+
<CustomButton type="vote" onClick={props.event} />
30+
<Heading>{Math.floor(Math.random() * 100)}</Heading>
31+
</Flex>
32+
);
33+
};
34+
export default Upvote;

0 commit comments

Comments
 (0)