@@ -5,18 +5,19 @@ import { logoutUser } from '../utils/auth';
5
5
import { navigate } from 'gatsby' ;
6
6
import { Query } from 'react-apollo' ;
7
7
import { PROFILE_QUERY } from '../utils/queries' ;
8
+ import { ProfileQueryQuery , User , Maybe , Tutorial } from '../graphqlTypes' ;
8
9
import { optionalChaining } from '../utils/helpers' ;
9
10
import { CenteredLoader } from '../components/shared/Loader' ;
10
11
11
12
const Profile = ( ) => {
12
13
return (
13
- < Query query = { PROFILE_QUERY } >
14
+ < Query < ProfileQueryQuery > query = { PROFILE_QUERY } >
14
15
{ ( { data, loading } ) => {
15
16
if ( loading ) {
16
17
return < CenteredLoader /> ;
17
18
}
18
19
if ( optionalChaining ( ( ) => data ! . viewer ! . user ) ) {
19
- return < ProfilePage user = { data . viewer . user } /> ;
20
+ return < ProfilePage user = { data ! . viewer ! . user } /> ;
20
21
}
21
22
navigate ( '/signup/' ) ;
22
23
return null ;
@@ -26,26 +27,23 @@ const Profile = () => {
26
27
} ;
27
28
28
29
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
+ } ;
49
47
} ;
50
48
51
49
const ProfilePage : React . FunctionComponent < ProfileProps > = ( { user } ) => {
@@ -68,7 +66,7 @@ const ProfilePage: React.FunctionComponent<ProfileProps> = ({ user }) => {
68
66
< button onClick = { ( ) => logoutUser ( ) } > Log out </ button >
69
67
< Heading > Upvoted Tutorials </ Heading >
70
68
< ul >
71
- { user . upvoted . map (
69
+ { user ! . upvoted ! . map (
72
70
a =>
73
71
a . tutorial && (
74
72
< li key = { a . tutorial . id } >
@@ -79,7 +77,7 @@ const ProfilePage: React.FunctionComponent<ProfileProps> = ({ user }) => {
79
77
</ ul >
80
78
< Heading > Bookmarked Tutorials </ Heading >
81
79
< ul >
82
- { user . bookmarked . map (
80
+ { user ! . bookmarked ! . map (
83
81
a =>
84
82
a . tutorial && (
85
83
< li key = { a . tutorial . id } >
@@ -88,9 +86,10 @@ const ProfilePage: React.FunctionComponent<ProfileProps> = ({ user }) => {
88
86
) ,
89
87
) }
90
88
</ ul >
89
+
91
90
< Heading > In Progress Tutorials </ Heading >
92
91
< ul >
93
- { user . progress . map (
92
+ { user ! . progress ! . map (
94
93
a =>
95
94
a . tutorial && (
96
95
< li key = { a . tutorial . id } >
0 commit comments