Skip to content

Commit 1171f18

Browse files
WithCurrentUser.ts -> WithCurrentUser.tsx
1 parent fc62674 commit 1171f18

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

packages/gatsby-theme/src/utils/auth/WithCurrentUser.ts renamed to packages/gatsby-theme/src/utils/auth/WithCurrentUser.tsx

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import React from 'react';
22
import { Query } from 'react-apollo';
33
import { optionalChaining } from '../helpers';
44
import gql from 'graphql-tag';
5-
import { User } from 'src/graphqlTypes';
5+
import { CurrentUserQuery, User } from 'src/graphqlTypes';
66

77
type ChildrenRenderProps = {
8-
user?: User | boolean;
8+
user?: Pick<User, 'id' | 'name' | 'avatarUrl' | 'githubHandle'> | boolean;
99
loading?: boolean;
1010
};
1111
type WithCurrentUserProps = {
@@ -14,20 +14,21 @@ type WithCurrentUserProps = {
1414

1515
const WithCurrentUser: React.FunctionComponent<WithCurrentUserProps> = ({
1616
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 {
17+
}) => {
18+
return (
19+
<Query<CurrentUserQuery> query={CURRENT_USER} >
20+
{({ data, loading }) => {
21+
if (loading) {
22+
return children({ loading });
23+
}
24+
if (optionalChaining(() => data!.viewer!.user)) {
25+
return children({ user: data!.viewer!.user });
26+
}
2627
return children({ user: false });
27-
}
28-
}}
29-
</Query>
30-
);
28+
}}
29+
</Query>
30+
)
31+
};
3132

3233
export const CURRENT_USER = gql`
3334
query currentUser {
@@ -36,11 +37,11 @@ export const CURRENT_USER = gql`
3637
user {
3738
id
3839
name
39-
avatarUrl
40-
githubHandle
41-
}
40+
avatarUrl
41+
githubHandle
4242
}
4343
}
44+
}
4445
`;
4546

4647
export default WithCurrentUser;

0 commit comments

Comments
 (0)