Permalink
Browse files

Implemented "Flag as Spam" button.

  • Loading branch information...
william-gross committed Oct 6, 2018
1 parent b5557d1 commit 7d15b499baba5d4c54677396a3af96230c42e439
@@ -23,7 +23,10 @@ const requests = {
put: (url, body) =>
superagent.put(`${API_ROOT}${url}`, body).use(tokenPlugin).then(responseBody),
post: (url, body) =>
superagent.post(`${API_ROOT}${url}`, body).use(tokenPlugin).then(responseBody)
superagent.post(`${API_ROOT}${url}`, body).use(tokenPlugin).then(responseBody),
patch: (url, body) =>
superagent.patch(`${API_ROOT}${url}`, body).use(tokenPlugin).then(responseBody)

};

const Auth = {
@@ -65,7 +68,9 @@ const Articles = {
update: article =>
requests.put(`/articles/${article.slug}`, { article: omitSlug(article) }),
create: article =>
requests.post('/articles', { article })
requests.post('/articles', { article }),
spam: slug =>
requests.patch(`/articles/${slug}`)
};

const Comments = {
@@ -2,18 +2,24 @@ import { Link } from 'react-router-dom';
import React from 'react';
import agent from '../../agent';
import { connect } from 'react-redux';
import { DELETE_ARTICLE } from '../../constants/actionTypes';
import { DELETE_ARTICLE, SPAM_ARTICLE } from '../../constants/actionTypes';

const mapDispatchToProps = dispatch => ({
onClickDelete: payload =>
dispatch({ type: DELETE_ARTICLE, payload })
dispatch({ type: DELETE_ARTICLE, payload }),
onClickSpam: payload =>
dispatch({ type: SPAM_ARTICLE, payload })
});

const ArticleActions = props => {
const article = props.article;
const del = () => {
props.onClickDelete(agent.Articles.del(article.slug))
};
const spam = () => {
props.onClickSpam(agent.Articles.spam(article.slug))
};

if (props.canModify) {
return (
<span>
@@ -31,7 +37,15 @@ const ArticleActions = props => {
</span>
);
}

if (!article.isSpam && props.currentUser !== null) {
return (
<span>
<button className="btn btn-outline-danger btn-sm" onClick={spam}>
<i className="ion-trash-a"></i> Flag Spam
</button>
</span>
);
}
return (
<span>
</span>
@@ -19,7 +19,7 @@ const ArticleMeta = props => {
</span>
</div>

<ArticleActions canModify={props.canModify} article={article} />
<ArticleActions canModify={props.canModify} article={article} currentUser={props.currentUser} />
</div>
);
};
@@ -47,7 +47,8 @@ class Article extends React.Component {
<h1>{this.props.article.title}</h1>
<ArticleMeta
article={this.props.article}
canModify={canModify} />
canModify={canModify}
currentUser={this.props.currentUser} />

</div>
</div>
@@ -33,4 +33,5 @@ export const UPDATE_FIELD_EDITOR = 'UPDATE_FIELD_EDITOR';
export const FOLLOW_USER = 'FOLLOW_USER';
export const UNFOLLOW_USER = 'UNFOLLOW_USER';
export const PROFILE_FAVORITES_PAGE_UNLOADED = 'PROFILE_FAVORITES_PAGE_UNLOADED';
export const PROFILE_FAVORITES_PAGE_LOADED = 'PROFILE_FAVORITES_PAGE_LOADED';
export const PROFILE_FAVORITES_PAGE_LOADED = 'PROFILE_FAVORITES_PAGE_LOADED';
export const SPAM_ARTICLE = 'SPAM_ARTICLE';
@@ -2,7 +2,8 @@ import {
ARTICLE_PAGE_LOADED,
ARTICLE_PAGE_UNLOADED,
ADD_COMMENT,
DELETE_COMMENT
DELETE_COMMENT,
SPAM_ARTICLE
} from '../constants/actionTypes';

export default (state = {}, action) => {
@@ -29,6 +30,11 @@ export default (state = {}, action) => {
...state,
comments: state.comments.filter(comment => comment.id !== commentId)
};
case SPAM_ARTICLE:
return {
...state,
article: { ...state.article, isSpam: true }
};
default:
return state;
}

0 comments on commit 7d15b49

Please sign in to comment.