File tree Expand file tree Collapse file tree 3 files changed +27
-7
lines changed Expand file tree Collapse file tree 3 files changed +27
-7
lines changed Original file line number Diff line number Diff line change @@ -52,11 +52,9 @@ class CreateLink extends Component {
52
52
postedById
53
53
} ,
54
54
update : ( store , { data : { createLink } } ) => {
55
-
56
55
const first = LINKS_PER_PAGE
57
56
const skip = 0
58
- const orderBy = "createdAt_DESC"
59
-
57
+ const orderBy = 'createdAt_DESC'
60
58
const data = store . readQuery ( {
61
59
query : ALL_LINKS_QUERY ,
62
60
variables : { first, skip, orderBy }
@@ -92,6 +90,9 @@ const CREATE_LINK_MUTATION = gql`
92
90
}
93
91
votes {
94
92
id
93
+ user {
94
+ id
95
+ }
95
96
}
96
97
}
97
98
}
Original file line number Diff line number Diff line change @@ -7,7 +7,6 @@ class Link extends Component {
7
7
render ( ) {
8
8
9
9
const userId = localStorage . getItem ( GC_USER_ID )
10
- console . log ( `Link - userId:` , userId )
11
10
return (
12
11
< div >
13
12
{ userId && < div onClick = { ( ) => this . _voteForLink ( ) } > ▲</ div > }
@@ -18,8 +17,14 @@ class Link extends Component {
18
17
}
19
18
20
19
_voteForLink = async ( ) => {
21
- const linkId = this . props . link . id
22
20
const userId = localStorage . getItem ( GC_USER_ID )
21
+ const voterIds = this . props . link . votes . map ( vote => vote . user . id )
22
+ if ( voterIds . includes ( userId ) ) {
23
+ console . log ( `User (${ userId } ) already voted for this link.` )
24
+ return
25
+ }
26
+
27
+ const linkId = this . props . link . id
23
28
await this . props . createVoteMutation ( {
24
29
variables : {
25
30
userId,
@@ -40,8 +45,14 @@ const CREATE_VOTE_MUTATION = gql`
40
45
link {
41
46
votes {
42
47
id
48
+ user {
49
+ id
50
+ }
43
51
}
44
52
}
53
+ user {
54
+ id
55
+ }
45
56
}
46
57
}
47
58
`
Original file line number Diff line number Diff line change @@ -38,8 +38,7 @@ class LinkList extends Component {
38
38
< button onClick = { ( ) => {
39
39
localStorage . removeItem ( GC_USER_ID )
40
40
localStorage . removeItem ( GC_AUTH_TOKEN )
41
- this . forceUpdate ( )
42
- { /*this.setState({})*/ }
41
+ this . forceUpdate ( ) // doesn't work as it should :(
43
42
} } > Logout</ button >
44
43
</ div >
45
44
}
@@ -133,8 +132,14 @@ class LinkList extends Component {
133
132
}
134
133
votes {
135
134
id
135
+ user {
136
+ id
137
+ }
136
138
}
137
139
}
140
+ user {
141
+ id
142
+ }
138
143
}
139
144
}
140
145
}
@@ -197,6 +202,9 @@ export const ALL_LINKS_QUERY = gql`
197
202
}
198
203
votes {
199
204
id
205
+ user {
206
+ id
207
+ }
200
208
}
201
209
}
202
210
_allLinksMeta {
You can’t perform that action at this time.
0 commit comments