-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from andela/ft-like-dislike-article-161348762
#161348762 Users can like or dislike an Article
- Loading branch information
Showing
47 changed files
with
1,905 additions
and
14,013 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
{ | ||
"presets": [ | ||
"@babel/preset-env", | ||
"@babel/preset-react" | ||
], | ||
"plugins": [ | ||
"@babel/plugin-proposal-class-properties" | ||
] | ||
"presets": [ | ||
"@babel/preset-env", | ||
"@babel/preset-react" | ||
], | ||
"plugins": [ | ||
"@babel/plugin-proposal-class-properties" | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import axios from 'axios'; | ||
import actionTypes from './actionTypes'; | ||
import APP_URL from '../utils/constants'; | ||
|
||
export const likeDislikeArticleAction = payload => ({ | ||
type: actionTypes.LIKEDISLIKE_ARTICLE, | ||
payload, | ||
}); | ||
|
||
export const likeDislikeArticleThunk = likeObj => (dispatch) => { | ||
const { articleId, likeDislikeStatus, token } = likeObj; | ||
const url = `${APP_URL}/articles/${articleId}/like_status`; | ||
const headerValue = { headers: { Authorization: `Token ${token}` } }; | ||
const payload = res => ({ | ||
results: res.data.results, | ||
likeStatus: likeObj.like_status, | ||
}); | ||
if (likeDislikeStatus) { // if a user has liked/disliked this article before | ||
return axios.put(url, likeObj, headerValue) | ||
.then((response) => { | ||
dispatch(likeDislikeArticleAction(payload(response))); | ||
}) | ||
.catch(() => {}); | ||
} | ||
return axios.post(url, likeObj, headerValue) | ||
.then((response) => { | ||
dispatch(likeDislikeArticleAction(payload(response))); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.