-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#165273540: Users should be able to follow each other #40
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// React libraries | ||
import React, { Component } from 'react'; | ||
|
||
// third-party libraries | ||
import PropTypes from 'prop-types'; | ||
|
||
// components | ||
import Button from 'components/Button'; | ||
|
||
// action creators | ||
import { | ||
fellowAndUnfollowAuthorActionCreator, | ||
} from 'store/actions/followActions'; | ||
|
||
export default class FollowProfileButton extends Component { | ||
followClick = () => { | ||
const { onButtonClick, username } = this.props; | ||
onButtonClick(fellowAndUnfollowAuthorActionCreator(username)); | ||
} | ||
|
||
unfollowClick = () => { | ||
const { onButtonClick, username } = this.props; | ||
onButtonClick(fellowAndUnfollowAuthorActionCreator(username)); | ||
} | ||
|
||
render() { | ||
const { following } = this.props; | ||
return ( | ||
<div> | ||
{ following | ||
? ( | ||
<Button | ||
variant="raised" | ||
color="secondary" | ||
btnClass="edit-btn" | ||
btnName="Unfollow" | ||
btnEvent={this.unfollowClick} | ||
onClick={this.unfollowClick} | ||
> | ||
Unfollow | ||
</Button> | ||
) | ||
: ( | ||
<Button | ||
variant="raised" | ||
color="primary" | ||
btnClass="edit-btn" | ||
btnName="Follow" | ||
btnEvent={this.followClick} | ||
onClick={this.followClick} | ||
> | ||
Follow | ||
</Button> | ||
) | ||
} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
FollowProfileButton.propTypes = { | ||
username: PropTypes.string.isRequired, | ||
following: PropTypes.bool.isRequired, | ||
onButtonClick: PropTypes.func.isRequired | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// third party libraries | ||
import { toast } from 'react-toastify'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parsing error: 'import' and 'export' may appear only with 'sourceType: module' |
||
|
||
// import axios instance | ||
import axios from 'utils/mainAxios'; | ||
|
||
// user constants | ||
import { | ||
FOLLOW_AUTHOR_ERROR, | ||
FOLLOW_AUTHOR_SUCCESS, | ||
UNFOLLOW_AUTHOR_FAILURE, | ||
UNFOLLOW_AUTHOR_SUCCESS, | ||
GET_FOLLOWERS_ERROR, | ||
GET_FOLLOWERS_SUCCESS, | ||
GET_FOLLOWING_ERROR, | ||
GET_FOLLOWING_SUCCESS, | ||
} from 'store/actions/followTypes'; | ||
|
||
/** | ||
* follow author action function on success | ||
* @param {string} response | ||
*/ | ||
export const followAuthorSuccess = response => ({ | ||
type: FOLLOW_AUTHOR_SUCCESS, | ||
response, | ||
}); | ||
|
||
/** | ||
* follow author action function on error | ||
* @param {string} error | ||
*/ | ||
export const followAuthorError = error => ({ | ||
type: FOLLOW_AUTHOR_ERROR, | ||
error, | ||
}); | ||
|
||
/** | ||
* follow author action function on success | ||
* @param {string} response | ||
*/ | ||
export const getFollowersSuccess = response => ({ | ||
type: GET_FOLLOWERS_SUCCESS, | ||
response, | ||
}); | ||
|
||
/** | ||
* get followers action function on error | ||
* @param {string} error | ||
*/ | ||
export const getFollowersError = error => ({ | ||
type: GET_FOLLOWERS_ERROR, | ||
error, | ||
}); | ||
|
||
/** | ||
* get followers action function on success | ||
* @param {string} response | ||
*/ | ||
export const getFollowingSuccess = response => ({ | ||
type: GET_FOLLOWING_SUCCESS, | ||
response, | ||
}); | ||
|
||
/** | ||
* follow author action function on error | ||
* @param {string} error | ||
*/ | ||
export const getFollowingError = error => ({ | ||
type: GET_FOLLOWING_ERROR, | ||
error, | ||
}); | ||
|
||
/** | ||
* action creator function for following authors | ||
* username as a parameter and dispatch as a function | ||
* @param {string} username | ||
*/ | ||
export const fellowAndUnfollowAuthorActionCreator = username => dispatch => axios | ||
.post(`authors/${username}/follow/`) | ||
.then(response => dispatch(followAuthorSuccess(response.data.profile))) | ||
.catch(error => dispatch(followAuthorError(error))); | ||
|
||
|
||
/** | ||
* action creator function for getting author's followers | ||
* username as a parameter and dispatch as a function | ||
* @param {string} username | ||
*/ | ||
export const getFollowersActionCreator = () => dispatch => axios | ||
.get('authors/followers/') | ||
.then((response) => { | ||
dispatch(getFollowersSuccess(response.data)); | ||
}) | ||
.catch(error => dispatch(getFollowersError(error))); | ||
|
||
/** | ||
* action creator function for getting author's followers | ||
* username as a parameter and dispatch as a function | ||
* @param {string} username | ||
*/ | ||
export const getFollowingActionCreator = () => dispatch => axios | ||
.get('authors/following/') | ||
.then((response) => { | ||
dispatch(getFollowingSuccess(response.data)); | ||
}) | ||
.catch(error => dispatch(getFollowingError(error))); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const FOLLOW_AUTHOR_ERROR = 'FOLLOW_AUTHOR_ERROR'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parsing error: 'import' and 'export' may appear only with 'sourceType: module' |
||
export const FOLLOW_AUTHOR_SUCCESS = 'FOLLOW_AUTHOR_SUCCESS'; | ||
export const GET_FOLLOWERS_ERROR = 'GET_FOLLOWERS_ERROR'; | ||
export const GET_FOLLOWERS_SUCCESS = 'GET_FOLLOWERS_SUCCESS'; | ||
export const GET_FOLLOWING_ERROR = 'GET_FOLLOWING_ERROR'; | ||
export const GET_FOLLOWING_SUCCESS = 'GET_FOLLOWING_SUCCESS'; | ||
export const UNFOLLOW_AUTHOR_FAILURE = 'UNFOLLOW_AUTHOR_FAILURE'; | ||
export const UNFOLLOW_AUTHOR_SUCCESS = 'UNFOLLOW_AUTHOR_SUCCESS'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing error: 'import' and 'export' may appear only with 'sourceType: module'