Skip to content

Commit 1df2e73

Browse files
committed
Merge branch 'main' of https://github.com/EOS-uiux-Solutions/user-story into bugs/notif
2 parents 38539b7 + 3676b93 commit 1df2e73

File tree

2 files changed

+22
-41
lines changed

2 files changed

+22
-41
lines changed

src/components/Vote.js

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React, { useState, useEffect } from 'react'
2-
import axios from 'axios'
3-
import { apiURL } from '../config.json'
42
import Modal from './Modal'
53
import { Link } from '@reach/router'
4+
import userStory from '../services/user_story'
65

76
const Vote = (props) => {
87
const { story } = props
@@ -40,52 +39,18 @@ const Vote = (props) => {
4039
let updatedFollowerIds = followers.filter(
4140
(id) => id !== JSON.stringify(userId)
4241
)
43-
const response = await axios.post(
44-
`${apiURL}/graphql`,
45-
{
46-
query: `
47-
mutation {
48-
updateUserStory(input: {where: {id: "${story.id}"} data: {followers: [${updatedFollowerIds}]}}){
49-
userStory{
50-
followers {
51-
id
52-
}
53-
}
54-
}
55-
}
56-
`
57-
},
58-
{
59-
withCredentials: true
60-
}
61-
)
42+
const response = await userStory.updateVotes(story.id, updatedFollowerIds)
6243
updatedFollowerIds = response.data.data.updateUserStory.userStory.followers.map(
6344
(follower) => JSON.stringify(follower.id)
6445
)
6546
setFollowers(updatedFollowerIds)
6647
setVoted(false)
6748
setVotes((votes) => votes - 1)
6849
} else {
69-
const response = await axios.post(
70-
`${apiURL}/graphql`,
71-
{
72-
query: `
73-
mutation {
74-
updateUserStory(input: {where: {id: "${story.id}"} data: {followers: [${followers}, "${userId}"]}}){
75-
userStory{
76-
followers {
77-
id
78-
}
79-
}
80-
}
81-
}
82-
`
83-
},
84-
{
85-
withCredentials: true
86-
}
87-
)
88-
const updatedFollowerIds = response.data.data.updateUserStory.userStory.followers.map(
50+
followers.push(JSON.stringify(userId))
51+
let updatedFollowerIds = followers
52+
const response = await userStory.updateVotes(story.id, updatedFollowerIds)
53+
updatedFollowerIds = response.data.data.updateUserStory.userStory.followers.map(
8954
(follower) => JSON.stringify(follower.id)
9055
)
9156
setFollowers(updatedFollowerIds)

src/services/user_story.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,22 @@ const userStory = {
328328
},
329329
postCommentReply: (data) => {
330330
return apiCall('/user-story-comment-threads', data)
331+
},
332+
updateVotes: (storyId, updatedFollowerIds) => {
333+
const updateVotesQuery = {
334+
query: `
335+
mutation {
336+
updateUserStory(input: {where: {id: "${storyId}"} data: {followers: [${updatedFollowerIds}]}}){
337+
userStory{
338+
followers {
339+
id
340+
}
341+
}
342+
}
343+
}
344+
`
345+
}
346+
return apiCall('/graphql', updateVotesQuery)
331347
}
332348
}
333349

0 commit comments

Comments
 (0)