From e8831a106d97683e5bb56cc9f98b61bee8ddf240 Mon Sep 17 00:00:00 2001 From: yaroslav Date: Thu, 15 Mar 2018 10:22:50 +0200 Subject: [PATCH] fetch comments HT% --- src/AC/index.js | 25 ++++++++++++++++++++++++- src/components/article-list/index.js | 15 +++++++++------ src/components/article/index.js | 21 +++++++++++++++++---- src/components/comment-list/index.js | 24 ++++++++++++++---------- src/components/comment.js | 15 ++++----------- src/constants/index.js | 1 + src/reducer/articles.js | 3 +-- src/reducer/comments.js | 15 +++++++++++++-- 8 files changed, 83 insertions(+), 36 deletions(-) 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 (