-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
343 additions
and
443 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 |
---|---|---|
|
@@ -25,6 +25,5 @@ yarn-error.log* | |
|
||
#idea | ||
.idea/ | ||
|
||
yarn.lock | ||
package-lock.json |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import axios from 'axios'; | ||
import axiosHeader from '../axios_config'; | ||
import { LIKE_SUCCESSFUL, LIKE_FAILURE } from './types'; | ||
import { fetchArticle } from "../actions/postArticles"; | ||
|
||
const apiURL = 'https://aholympian.herokuapp.com/api'; | ||
export const success = message => ({ type: LIKE_SUCCESSFUL, payload: message }); | ||
export const failure = errors => ({ type: LIKE_FAILURE, payload: errors }); | ||
|
||
|
||
|
||
const likeArticle = data => (dispatch) => { | ||
const { action, slug } = data; | ||
axios.post(`${apiURL}/articles/${slug}/${action}`, {}, axiosHeader | ||
) | ||
.then((response) => { | ||
dispatch(success(response.data)); | ||
dispatch(fetchArticle(slug)); | ||
}) | ||
.catch((error) => { | ||
dispatch(failure(JSON.stringify(error.response.data))); | ||
}); | ||
}; | ||
|
||
export default likeArticle; |
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
7 changes: 0 additions & 7 deletions
7
src/components/Articles/tests/__snapshots__/viewarticle.test.js.snap
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import React, { Component } from 'react'; | ||
import { Icon, Label, Button } from 'semantic-ui-react'; | ||
import { connect } from 'react-redux'; | ||
import likeArticle from '../../actions/likearticle'; | ||
|
||
class ArticleLiking extends Component { | ||
constructor(props) { | ||
super(props) | ||
this.state = { | ||
likes_count: null, | ||
dislikes_count: null, | ||
status: '', | ||
liked: false, | ||
disliked: false, | ||
}; | ||
} | ||
|
||
|
||
componentDidMount() { | ||
this.setState({ | ||
likes_count: this.props.article.article.likes_count, | ||
dislikes_count: this.props.article.article.dislikes_count, | ||
status: this.state.status, | ||
}); | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (nextProps.likesData !== this.props.likesData) { | ||
this.setState({ ...nextProps.likesData }); | ||
} | ||
this.setState({ | ||
likes_count: nextProps.article.article.likes_count, | ||
dislikes_count: nextProps.article.article.dislikes_count, | ||
}); | ||
} | ||
|
||
handleLike = () => { | ||
const data = { | ||
slug: this.props.slug, | ||
action: 'like', | ||
}; | ||
this.setState({ | ||
status: data.action, | ||
}); | ||
this.props.likeArticle(data); | ||
}; | ||
|
||
handleunLike = () => { | ||
const data = { | ||
slug: this.props.slug, | ||
action: 'unlike', | ||
}; | ||
this.setState({ | ||
status: data.action, | ||
}); | ||
this.props.likeArticle(data); | ||
}; | ||
|
||
handleDislike = () => { | ||
const data = { | ||
slug: this.props.slug, | ||
action: 'dislike', | ||
}; | ||
this.setState({ status: data.action }); | ||
this.props.likeArticle(data); | ||
}; | ||
|
||
render() { | ||
|
||
let likeColor = ''; | ||
let dislikeColor = ''; | ||
switch (this.state.status) { | ||
case 'like': | ||
likeColor = 'blue'; | ||
dislikeColor = ''; | ||
break; | ||
case 'dislike': | ||
dislikeColor = 'blue'; | ||
likeColor = ''; | ||
break; | ||
default: | ||
dislikeColor = ''; | ||
likeColor = ''; | ||
} | ||
|
||
return ( | ||
<div> | ||
<Button | ||
as="div" | ||
labelPosition="right" | ||
className="like-buttton" | ||
onClick={this.handleLike} | ||
> | ||
<Button color={likeColor}> | ||
<Icon name="thumbs up" /> | ||
Like | ||
</Button> | ||
<Label as="a" basic color={likeColor} pointing="left"> | ||
{this.state.likes_count ? this.state.likes_count : 0} | ||
</Label> | ||
</Button> | ||
<Button | ||
as="div" | ||
labelPosition="right" | ||
className="dislike-button" | ||
onClick={this.handleDislike} | ||
> | ||
<Button color={dislikeColor}> | ||
<Icon name="thumbs down" /> | ||
Dislike | ||
</Button> | ||
<Label as="a" basic color={dislikeColor} pointing="left"> | ||
{this.state.dislikes_count ? this.state.dislikes_count : 0} | ||
</Label> | ||
</Button> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const mapDispatchToProps = dispatch => ({ | ||
likeArticle: data => dispatch(likeArticle(data)), | ||
}); | ||
|
||
const mapStateToProps = state => ({ | ||
article: state.articles.item, | ||
likesData: state.send_like.data | ||
}); | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps, | ||
)(ArticleLiking); |
Oops, something went wrong.