Skip to content

Commit fc62674

Browse files
committed
revisions to pull request
1 parent e74cb5a commit fc62674

File tree

12 files changed

+94
-76
lines changed

12 files changed

+94
-76
lines changed

packages/gatsby-theme/src/Apollo.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ import { HttpLink } from 'apollo-link-http';
44
import { InMemoryCache } from 'apollo-cache-inmemory';
55
import fetch from 'isomorphic-fetch';
66
import config from '../config';
7-
import { getAuthToken } from './utils/auth/auth';
7+
import { getAuthToken } from './utils/auth';
88

99
const authLink = setContext((_, { headers }) => {
10-
// get the authentication token from local storage if it exists
11-
const token = getAuthToken();
12-
// return the headers to the context so httpLink can read them
13-
return {
14-
headers: {
15-
...headers,
16-
authorization: token ? `Bearer ${token}` : "",
17-
}
18-
}
10+
// get the authentication token from local storage if it exists
11+
const token = getAuthToken();
12+
// return the headers to the context so httpLink can read them
13+
return {
14+
headers: {
15+
...headers,
16+
authorization: token ? `Bearer ${token}` : '',
17+
},
18+
};
1919
});
2020
const httpLink = new HttpLink({ uri: config.apiUrl, fetch });
2121
export const client = new ApolloClient({
22-
link: authLink.concat(httpLink),
23-
cache: new InMemoryCache(),
22+
link: authLink.concat(httpLink),
23+
cache: new InMemoryCache(),
2424
});

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
22
import { Text, Image, Flex } from './shared/base';
33
import { Link } from 'gatsby';
4-
import CustomButton from './CustomButton';
5-
import { loginUser } from '../utils/auth/auth';
4+
import { GithubButton } from './buttons';
5+
import { loginUser } from '../utils/auth';
66
import WithCurrentUser from '../utils/auth/WithCurrentUser';
77
import { CenteredLoader } from '../components/Loader';
88

@@ -17,9 +17,7 @@ const Account = () => {
1717
return <Profile user={user} />;
1818
} else {
1919
return (
20-
<CustomButton onClick={() => loginUser()} type="github">
21-
Sign up
22-
</CustomButton>
20+
<GithubButton onClick={() => loginUser()}>Sign up</GithubButton>
2321
);
2422
}
2523
}}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { Card, Image, Heading, Flex } from './shared/base';
33
import { authors } from '../utils/sampleData';
44
import AuthorList from './AuthorList';
5-
import CustomButton from './CustomButton';
5+
import { SpectrumButton } from './buttons';
66

77
type SidebarProps = {
88
tutorialTitle: string;
@@ -26,7 +26,7 @@ export const Sidebar: React.FunctionComponent<SidebarProps> = ({
2626
))}
2727
</ul>
2828
<AuthorList authors={authors} />
29-
<CustomButton type="spectrum"> Get help on Spectrum </CustomButton>
29+
<SpectrumButton> Get help on Spectrum </SpectrumButton>
3030
</div>
3131
);
3232
};

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { Heading, Flex } from './shared/base';
3-
import CustomButton from './CustomButton';
4-
import { loginUser } from '../utils/auth/auth';
3+
import { VoteButton } from './buttons';
4+
import { loginUser } from '../utils/auth/';
55
import WithCurrentUser from '../utils/auth/WithCurrentUser';
66

77
// Still to-do:
@@ -30,7 +30,7 @@ type UpvoteDataProps = {
3030
const UpvoteData: React.FunctionComponent<UpvoteDataProps> = ({ event }) => {
3131
return (
3232
<Flex flexDirection="column" alignItems="center" justifyContent="center">
33-
<CustomButton type="vote" onClick={event} />
33+
<VoteButton onClick={event} />
3434
<Heading>{Math.floor(Math.random() * 100)}</Heading>
3535
</Flex>
3636
);

packages/gatsby-theme/src/components/CustomButton.tsx renamed to packages/gatsby-theme/src/components/buttons.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
import React from 'react';
2-
import { ButtonProps } from './shared/base.d';
2+
import { ButtonProps } from './shared/base';
33
import { Flex, Image, Button } from './shared/base';
44

5+
export const VoteButton: React.FunctionComponent<ButtonProps> = props => (
6+
<CustomButton {...props} type="vote" />
7+
);
8+
9+
export const GithubButton: React.FunctionComponent<ButtonProps> = props => (
10+
<CustomButton {...props} type="github" />
11+
);
12+
13+
export const TutorialButton: React.FunctionComponent<ButtonProps> = props => (
14+
<CustomButton {...props} type="tutorial" />
15+
);
16+
17+
export const SpectrumButton: React.FunctionComponent<ButtonProps> = props => (
18+
<CustomButton {...props} type="tutorial" />
19+
);
20+
521
export const CustomButton: React.FunctionComponent<
622
ButtonProps & {
723
type?: 'github' | 'tutorial' | 'spectrum' | 'vote' | 'default';
@@ -58,5 +74,3 @@ const customButtonTypes: CustomButtonType = {
5874
bg: 'primary',
5975
},
6076
};
61-
62-
export default CustomButton;

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import AuthorList from '../AuthorList';
66
import TutorialHeader from '../overview/TutorialHeader';
77
import { Heading, Flex, Box } from '../shared/base';
88
import ProgressBar from '../overview/ProgressBar';
9-
import CustomButton from '../CustomButton';
9+
import { GithubButton, SpectrumButton, TutorialButton } from '../buttons';
1010
import { Content } from '../shared/styledHelpers';
1111
import { authors } from '../../utils/sampleData';
1212
import { graphql } from 'gatsby';
@@ -29,13 +29,13 @@ const PageTemplate: React.FunctionComponent<PageTemplateProps> = ({ data }) => {
2929
/>
3030
</Box>
3131
<Box width={1 / 4} m={3}>
32-
<CustomButton type="tutorial">Continue Tutorial</CustomButton>
32+
<TutorialButton>Continue Tutorial</TutorialButton>
3333
<Box m={3}>
3434
<ProgressBar percentage={33} width={100} />
3535
</Box>
3636
<Flex>
37-
<CustomButton type="github">Github</CustomButton>
38-
<CustomButton type="spectrum">Spectrum</CustomButton>
37+
<GithubButton>Github</GithubButton>
38+
<SpectrumButton>Spectrum</SpectrumButton>
3939
</Flex>
4040
<AuthorList authors={authors} />
4141
</Box>
@@ -46,10 +46,7 @@ const PageTemplate: React.FunctionComponent<PageTemplateProps> = ({ data }) => {
4646
let num = index + 1;
4747
return (
4848
<div>
49-
<Chapter
50-
num={num < 10 ? `0${num}` : num}
51-
tutorial = {mdx.node}
52-
/>
49+
<Chapter num={num < 10 ? `0${num}` : num} tutorial={mdx.node} />
5350
</div>
5451
);
5552
})}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import Layout from '../components/layout';
33
import { Text, Image, Flex } from '../components/shared/base';
4-
import { logoutUser } from '../utils/auth/auth';
4+
import { logoutUser } from '../utils/auth';
55
import { navigate } from 'gatsby';
66
import WithCurrentUser from '../utils/auth/WithCurrentUser';
77
import { CenteredLoader } from '../components/Loader';

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import Layout from '../components/layout';
33
import { navigate } from 'gatsby';
44
import { CenteredLoader } from '../components/Loader';
55
import { Flex, Text, Box } from '../components/shared/base';
6-
import CustomButton from '../components/CustomButton';
6+
import { GithubButton } from '../components/buttons';
77
import WithCurrentUser from '../utils/auth/WithCurrentUser';
8-
import { loginUser } from '../utils/auth/auth';
8+
import { loginUser } from '../utils/auth/';
99

1010
const Signup = () => {
1111
return (
@@ -35,9 +35,9 @@ const SignupPage = () => {
3535
Lorem ipsum dolor sit amet.
3636
</Text>
3737
<Box m={4}>
38-
<CustomButton onClick={() => loginUser()} type="github">
38+
<GithubButton onClick={() => loginUser()}>
3939
Sign in with Github
40-
</CustomButton>
40+
</GithubButton>
4141
</Box>
4242
</Flex>
4343
</Layout>

packages/gatsby-theme/src/utils/auth/WithCurrentUser.js

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React from 'react';
2+
import { Query } from 'react-apollo';
3+
import { optionalChaining } from '../helpers';
4+
import gql from 'graphql-tag';
5+
import { User } from 'src/graphqlTypes';
6+
7+
type ChildrenRenderProps = {
8+
user?: User | boolean;
9+
loading?: boolean;
10+
};
11+
type WithCurrentUserProps = {
12+
children: (renderProps: ChildrenRenderProps) => any;
13+
};
14+
15+
const WithCurrentUser: React.FunctionComponent<WithCurrentUserProps> = ({
16+
children,
17+
}) => (
18+
<Query query={CURRENT_USER}>
19+
{({ data, error, loading }) => {
20+
if (loading) {
21+
return children({ loading });
22+
}
23+
if (optionalChaining(() => data.viewer.user)) {
24+
return children({ user: data.viewer.user });
25+
} else {
26+
return children({ user: false });
27+
}
28+
}}
29+
</Query>
30+
);
31+
32+
export const CURRENT_USER = gql`
33+
query currentUser {
34+
viewer {
35+
id
36+
user {
37+
id
38+
name
39+
avatarUrl
40+
githubHandle
41+
}
42+
}
43+
}
44+
`;
45+
46+
export default WithCurrentUser;

0 commit comments

Comments
 (0)