From 36ad8d5c98eb241a7cb93c583dcaa30792e68089 Mon Sep 17 00:00:00 2001 From: data Date: Thu, 4 Jul 2019 09:21:37 -0400 Subject: [PATCH] show number of Comments for Articles --- src/App.js | 24 +++++++++++++++++++++++- src/components/articles.js | 5 +++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index 1e86f1b..70937a1 100644 --- a/src/App.js +++ b/src/App.js @@ -111,11 +111,33 @@ class App extends React.Component { } } + async fetchComments() { + try { + const { data } = await axios.get(API + '/api/comments') + return data + } catch (error) { + console.log(error) + this.setState({ error }) + } + } + + async fetchVotes() { + try { + const { data } = await axios.get(API + '/api/votes') + return data + } catch (error) { + console.log(error) + this.setState({ error }) + } + } + async fetchData() { const articles = await this.fetchArticles() const tasks = await this.fetchTasks() const projects = await this.fetchProjects() - await this.setState({ loading: false, articles, tasks, projects }) + const comments = await this.fetchComments() + const votes = await this.fetchVotes() + await this.setState({ loading: false, articles, tasks, projects, comments, votes }) } componentDidMount() { diff --git a/src/components/articles.js b/src/components/articles.js index 9dc2d9f..f9225f5 100644 --- a/src/components/articles.js +++ b/src/components/articles.js @@ -20,6 +20,11 @@ function Articles(props) { > {article.title}{' '} + ))}