2021-04-15 19:41:02 +00:00
|
|
|
import { useQuery, gql } from '@apollo/client'
|
|
|
|
import Comment from './comment'
|
2021-04-17 18:15:18 +00:00
|
|
|
import { COMMENTS } from '../fragments'
|
2021-04-15 19:41:02 +00:00
|
|
|
|
2021-04-17 18:15:18 +00:00
|
|
|
export default function Comments ({ parentId }) {
|
2021-04-15 19:41:02 +00:00
|
|
|
const { data } = useQuery(
|
2021-04-17 18:15:18 +00:00
|
|
|
gql`
|
|
|
|
${COMMENTS}
|
|
|
|
|
|
|
|
{
|
2021-04-15 19:41:02 +00:00
|
|
|
comments(parentId: ${parentId}) {
|
2021-04-17 18:15:18 +00:00
|
|
|
...CommentsRecursive
|
2021-04-15 19:41:02 +00:00
|
|
|
}
|
|
|
|
}`
|
|
|
|
)
|
|
|
|
|
|
|
|
if (!data) return null
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='mt-5'>
|
|
|
|
{data.comments.map(item => (
|
2021-04-17 18:15:18 +00:00
|
|
|
<div key={item.id} className='mt-2'>
|
2021-04-15 19:41:02 +00:00
|
|
|
<Comment item={item} />
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|