@@ -48,19 +48,6 @@ const issuesOfRepositoryQuery = `
4848 }
4949` ;
5050
51- const addReactionToIssueMutation = `
52- mutation ($issueId: ID!) {
53- addReaction(input:{subjectId:$issueId,content:HOORAY}) {
54- reaction {
55- content
56- }
57- subject {
58- id
59- }
60- }
61- }
62- ` ;
63-
6451const addStarToRepositoryMutation = `
6552 mutation ($repositoryId: ID!) {
6653 addStar(input:{starrableId:$repositoryId}) {
@@ -71,13 +58,6 @@ const addStarToRepositoryMutation = `
7158 }
7259` ;
7360
74- const addReactionToIssue = issueId => {
75- return axiosGitHubGraphQL . post ( '' , {
76- query : addReactionToIssueMutation ,
77- variables : { issueId } ,
78- } ) ;
79- } ;
80-
8161const addStarToRepository = repositoryId => {
8262 return axiosGitHubGraphQL . post ( '' , {
8363 query : addStarToRepositoryMutation ,
@@ -94,48 +74,6 @@ const getIssuesOfRepository = path => {
9474 } ) ;
9575} ;
9676
97- const updatedIssue = ( issue , newReaction ) => {
98- return {
99- ...issue ,
100- node : {
101- ...issue . node ,
102- reactions : {
103- ...issue . node . reactions ,
104- edges : [ ...issue . node . reactions . edges , { node : newReaction } ] ,
105- } ,
106- } ,
107- } ;
108- } ;
109-
110- const updatedIssueInState = mutationResult => state => {
111- const { issues } = state . organization . repository ;
112- const { reaction, subject } = mutationResult . data . data . addReaction ;
113-
114- const newReaction = { content : reaction . content , id : subject . id } ;
115-
116- const updatedIssues = issues . edges . map ( issue => {
117- if ( issue . node . id === subject . id ) {
118- return updatedIssue ( issue , newReaction ) ;
119- } else {
120- return issue ;
121- }
122- } ) ;
123-
124- return {
125- ...state ,
126- organization : {
127- ...state . organization ,
128- repository : {
129- ...state . organization . repository ,
130- issues : {
131- ...state . organization . repository . issues ,
132- edges : updatedIssues ,
133- } ,
134- } ,
135- } ,
136- } ;
137- } ;
138-
13977const resolveAddStarMutation = mutationResult => state => {
14078 const {
14179 viewerHasStarred,
@@ -183,13 +121,7 @@ class App extends Component {
183121 ) ;
184122 } ;
185123
186- onAddReactionToIssue = issueId => {
187- addReactionToIssue ( issueId ) . then ( mutationResult =>
188- this . setState ( updatedIssueInState ( mutationResult ) ) ,
189- ) ;
190- } ;
191-
192- onAddStarToRepository = repositoryId => {
124+ onStarToRepository = repositoryId => {
193125 addStarToRepository ( repositoryId ) . then ( mutationResult =>
194126 this . setState ( resolveAddStarMutation ( mutationResult ) ) ,
195127 ) ;
@@ -222,8 +154,7 @@ class App extends Component {
222154 < Organization
223155 organization = { organization }
224156 errors = { errors }
225- onAddReactionToIssue = { this . onAddReactionToIssue }
226- onAddStarToRepository = { this . onAddStarToRepository }
157+ onStarToRepository = { this . onStarToRepository }
227158 />
228159 ) : (
229160 < p > No information yet ...</ p >
@@ -236,8 +167,7 @@ class App extends Component {
236167const Organization = ( {
237168 organization,
238169 errors,
239- onAddReactionToIssue,
240- onAddStarToRepository,
170+ onStarToRepository,
241171} ) => {
242172 if ( errors ) {
243173 return (
@@ -256,18 +186,13 @@ const Organization = ({
256186 </ p >
257187 < Repository
258188 repository = { organization . repository }
259- onAddReactionToIssue = { onAddReactionToIssue }
260- onAddStarToRepository = { onAddStarToRepository }
189+ onStarToRepository = { onStarToRepository }
261190 />
262191 </ div >
263192 ) ;
264193} ;
265194
266- const Repository = ( {
267- repository,
268- onAddReactionToIssue,
269- onAddStarToRepository,
270- } ) => (
195+ const Repository = ( { repository, onStarToRepository } ) => (
271196 < div >
272197 < p >
273198 < strong > In Repository:</ strong >
@@ -276,7 +201,7 @@ const Repository = ({
276201
277202 < button
278203 type = "button"
279- onClick = { ( ) => onAddStarToRepository ( repository . id ) }
204+ onClick = { ( ) => onStarToRepository ( repository . id ) }
280205 >
281206 { repository . viewerHasStarred ? 'Unstar' : 'Star' }
282207 </ button >
@@ -286,13 +211,6 @@ const Repository = ({
286211 < li key = { issue . node . id } >
287212 < a href = { issue . node . url } > { issue . node . title } </ a >
288213
289- < button
290- type = "button"
291- onClick = { ( ) => onAddReactionToIssue ( issue . node . id ) }
292- >
293- Say "Horray"
294- </ button >
295-
296214 < ul >
297215 { issue . node . reactions . edges . map ( reaction => (
298216 < li key = { reaction . node . id } > { reaction . node . content } </ li >
0 commit comments