Skip to content

Commit 1eb427c

Browse files
committed
fix profile page props
1 parent fe20bcb commit 1eb427c

File tree

5 files changed

+43
-42
lines changed

5 files changed

+43
-42
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const TutorialLayout: React.FunctionComponent<TutorialLayoutProps> = ({
8686
<a href={nextChapterPath}>
8787
<ChapterMutation
8888
gatsbyID={gatsbyID}
89-
currentChapter={currentChapterIndex + 1}
89+
chapter={currentChapterIndex + 1}
9090
/>
9191
</a>
9292
</Layout>

packages/gatsby-theme/src/components/tutorial/AuthorsProgressBox.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import AuthorList from './AuthorList';
33
import { authors } from '../../utils/sampleData';
44
import ProgressBar from '../shared/ProgressBar';
55
import { getTutorialbyGatsbyID } from '../../utils/queries';
6+
import { GetTutorialbyGatsbyIdQuery } from '../../graphqlTypes';
67
import { Query } from 'react-apollo';
78
import {
89
GithubButton,
@@ -13,20 +14,23 @@ import { Flex, Box } from '../shared/base';
1314
import { optionalChaining, percent } from '../../utils/helpers';
1415

1516
const AuthorsProgressBox = ({ gatsbyID, chapterPaths }) => (
16-
<Query query={getTutorialbyGatsbyID} variables={{ gatsbyID: gatsbyID }}>
17+
<Query<GetTutorialbyGatsbyIdQuery>
18+
query={getTutorialbyGatsbyID}
19+
variables={{ gatsbyID: gatsbyID }}
20+
>
1721
{({ data }) => {
1822
let buttonText = 'Start Tutorial';
1923
let percentage = 0;
2024
let currentChapter =
2125
optionalChaining(
22-
() => data.getTutorialbyGatsbyID.viewerUserTutorial.currentChapter,
26+
() => data!.getTutorialbyGatsbyID!.viewerUserTutorial!.currentChapter,
2327
) || 0;
2428
//This link you to the next chapter you have not done
2529
let currentChapterPath = chapterPaths[0];
2630
if (currentChapter) {
2731
percentage = percent(
28-
data.getTutorialbyGatsbyID.numberofChapters,
29-
data.getTutorialbyGatsbyID.viewerUserTutorial.currentChapter,
32+
data!.getTutorialbyGatsbyID!.numberofChapters,
33+
data!.getTutorialbyGatsbyID!.viewerUserTutorial!.currentChapter,
3034
);
3135
buttonText = 'Continue Tutorial';
3236

packages/gatsby-theme/src/components/tutorial/ChapterMutation.tsx

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
import * as React from 'react';
22
import { upsertCurrentChapter } from '../../utils/queries';
3+
import {
4+
UpsertCurrentChapterMutation,
5+
UpsertCurrentChapterMutationVariables,
6+
} from '../../graphqlTypes';
37
import { Mutation } from 'react-apollo';
48
import { loginUser } from '../../utils/auth';
59
import { handleMutationResponse, ApiErrors } from '../../utils/errorHandling';
610
import { Button } from '../shared/base';
711

8-
type ChapterMutationProps = {
9-
gatsbyID: any;
10-
currentChapter: any;
11-
};
12-
13-
const ChapterMutation: React.FunctionComponent<ChapterMutationProps> = ({
14-
gatsbyID,
15-
currentChapter,
16-
}) => (
17-
<Mutation
12+
const ChapterMutation: React.FunctionComponent<
13+
UpsertCurrentChapterMutationVariables
14+
> = ({ gatsbyID, chapter }) => (
15+
<Mutation<UpsertCurrentChapterMutation>
1816
mutation={upsertCurrentChapter}
1917
variables={{
2018
gatsbyID: gatsbyID,
21-
chapter: currentChapter,
19+
chapter: chapter,
2220
}}
2321
>
2422
{currentChapter => {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { SpectrumButton } from '../shared/buttons';
66

77
type SidebarProps = {
88
tutorialTitle: string;
9-
chapters: Chapter;
9+
chapters: Chapter[];
1010
};
1111
type Chapter = {
1212
chapterTitle: string;

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

+24-25
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ import { logoutUser } from '../utils/auth';
55
import { navigate } from 'gatsby';
66
import { Query } from 'react-apollo';
77
import { PROFILE_QUERY } from '../utils/queries';
8+
import { ProfileQueryQuery, User, Maybe, Tutorial } from '../graphqlTypes';
89
import { optionalChaining } from '../utils/helpers';
910
import { CenteredLoader } from '../components/shared/Loader';
1011

1112
const Profile = () => {
1213
return (
13-
<Query query={PROFILE_QUERY}>
14+
<Query<ProfileQueryQuery> query={PROFILE_QUERY}>
1415
{({ data, loading }) => {
1516
if (loading) {
1617
return <CenteredLoader />;
1718
}
1819
if (optionalChaining(() => data!.viewer!.user)) {
19-
return <ProfilePage user={data.viewer.user} />;
20+
return <ProfilePage user={data!.viewer!.user} />;
2021
}
2122
navigate('/signup/');
2223
return null;
@@ -26,26 +27,23 @@ const Profile = () => {
2627
};
2728

2829
type ProfileProps = {
29-
user: User;
30-
};
31-
32-
type User = {
33-
id: string;
34-
avatarUrl: string;
35-
name: string;
36-
githubHandle: string;
37-
bio: string;
38-
upvoted: [Tutorials];
39-
bookmarked: [Tutorials];
40-
};
41-
42-
type Tutorials = {
43-
tutorial: Tutorial;
44-
};
45-
46-
type Tutorial = {
47-
id: 'string';
48-
name: 'string';
30+
user: Pick<User, 'id' | 'name' | 'githubHandle' | 'avatarUrl' | 'bio'> & {
31+
readonly upvoted: Maybe<
32+
ReadonlyArray<{
33+
readonly tutorial: Maybe<Pick<Tutorial, 'id' | 'name'>>;
34+
}>
35+
>;
36+
readonly bookmarked: Maybe<
37+
ReadonlyArray<{
38+
readonly tutorial: Maybe<Pick<Tutorial, 'id' | 'name'>>;
39+
}>
40+
>;
41+
readonly progress: Maybe<
42+
ReadonlyArray<{
43+
readonly tutorial: Maybe<Pick<Tutorial, 'id' | 'name'>>;
44+
}>
45+
>;
46+
};
4947
};
5048

5149
const ProfilePage: React.FunctionComponent<ProfileProps> = ({ user }) => {
@@ -68,7 +66,7 @@ const ProfilePage: React.FunctionComponent<ProfileProps> = ({ user }) => {
6866
<button onClick={() => logoutUser()}> Log out </button>
6967
<Heading> Upvoted Tutorials </Heading>
7068
<ul>
71-
{user.upvoted.map(
69+
{user!.upvoted!.map(
7270
a =>
7371
a.tutorial && (
7472
<li key={a.tutorial.id}>
@@ -79,7 +77,7 @@ const ProfilePage: React.FunctionComponent<ProfileProps> = ({ user }) => {
7977
</ul>
8078
<Heading> Bookmarked Tutorials </Heading>
8179
<ul>
82-
{user.bookmarked.map(
80+
{user!.bookmarked!.map(
8381
a =>
8482
a.tutorial && (
8583
<li key={a.tutorial.id}>
@@ -88,9 +86,10 @@ const ProfilePage: React.FunctionComponent<ProfileProps> = ({ user }) => {
8886
),
8987
)}
9088
</ul>
89+
9190
<Heading> In Progress Tutorials </Heading>
9291
<ul>
93-
{user.progress.map(
92+
{user!.progress!.map(
9493
a =>
9594
a.tutorial && (
9695
<li key={a.tutorial.id}>

0 commit comments

Comments
 (0)