stacker.news/components/comments.js

24 lines
607 B
JavaScript
Raw Normal View History

2021-04-22 17:14:32 -05:00
import { useQuery } from '@apollo/client'
import Comment, { CommentSkeleton } from './comment'
2021-04-15 14:41:02 -05:00
2021-04-26 19:55:48 -05:00
export default function Comments ({ comments, ...props }) {
return comments.map(item => (
2021-04-28 14:30:14 -05:00
<Comment key={item.id} item={item} {...props} />
2021-04-26 19:55:48 -05:00
))
}
export function CommentsSkeleton () {
2021-05-05 13:13:14 -05:00
return <CommentSkeleton skeletonChildren={7} />
2021-04-26 19:55:48 -05:00
}
export function CommentsQuery ({ query, ...props }) {
2021-04-22 17:14:32 -05:00
const { loading, error, data } = useQuery(query)
2021-04-17 13:15:18 -05:00
2021-04-22 17:14:32 -05:00
if (error) return <div>Failed to load!</div>
if (loading) {
2021-04-26 19:55:48 -05:00
return <CommentsSkeleton />
2021-04-22 17:14:32 -05:00
}
2021-04-15 14:41:02 -05:00
2021-04-26 19:55:48 -05:00
return <Comments comments={data.comments} {...props} />
2021-04-15 14:41:02 -05:00
}