diff --git a/src/AC/index.js b/src/AC/index.js index 401b5b1..f7c6a7a 100644 --- a/src/AC/index.js +++ b/src/AC/index.js @@ -1,6 +1,6 @@ import { INCREMENT, DELETE_ARTICLE, CHANGE_DATE_RANGE, CHANGE_SELECTION, ADD_COMMENT, LOAD_ALL_ARTICLES, LOAD_ARTICLE, - START, SUCCESS, FAIL + START, SUCCESS, FAIL, LOAD_COMMENTS } from '../constants' export function increment() { @@ -74,4 +74,27 @@ export function loadArticleById(id) { })) }, 1000) } +} + +export function loadCommenstById(id) { + return (dispatch) => { + dispatch({ + type: LOAD_COMMENTS + START, + payload: {id} + }) + + fetch(`/api/comment?article=${id}`) + .then(res => { + return res.json() + }) + .then(response => dispatch({ + type: LOAD_COMMENTS + SUCCESS, + payload: {id, response} + })) + .catch(error => dispatch({ + type: LOAD_COMMENTS + FAIL, + payload: {id, error} + })) + + } } \ No newline at end of file diff --git a/src/components/article-list/index.js b/src/components/article-list/index.js index 9968428..e50dd95 100644 --- a/src/components/article-list/index.js +++ b/src/components/article-list/index.js @@ -24,15 +24,18 @@ export class ArticleList extends Component { render() { const { articles, openItemId, toggleItem, loading } = this.props if (loading) return - const articleElements = articles.map(article => -
  • + + + const articleElements = articles.map(article => ( +
  • - ) + )) return (