show number of Comments for Articles

This commit is contained in:
data 2019-07-04 09:21:37 -04:00
parent 7072045613
commit 36ad8d5c98
2 changed files with 28 additions and 1 deletions

View File

@ -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() {

View File

@ -20,6 +20,11 @@ function Articles(props) {
>
{article.title}{' '}
</button>
<button
className="btn ml-1 float-right"
>
{props.comments.map(c => c.articleId === article.id).length} comments
</button>
</li>
))}