show number of Comments for Articles
This commit is contained in:
parent
7072045613
commit
36ad8d5c98
24
src/App.js
24
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() {
|
async fetchData() {
|
||||||
const articles = await this.fetchArticles()
|
const articles = await this.fetchArticles()
|
||||||
const tasks = await this.fetchTasks()
|
const tasks = await this.fetchTasks()
|
||||||
const projects = await this.fetchProjects()
|
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() {
|
componentDidMount() {
|
||||||
|
@ -20,6 +20,11 @@ function Articles(props) {
|
|||||||
>
|
>
|
||||||
{article.title}{' '}
|
{article.title}{' '}
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
className="btn ml-1 float-right"
|
||||||
|
>
|
||||||
|
{props.comments.map(c => c.articleId === article.id).length} comments
|
||||||
|
</button>
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user