stacker.news/components/comments.js

28 lines
693 B
JavaScript
Raw Normal View History

2021-04-22 22:14:32 +00:00
import { useQuery } from '@apollo/client'
import Comment, { CommentSkeleton } from './comment'
2021-04-15 19:41:02 +00:00
2021-04-27 00:55:48 +00:00
export default function Comments ({ comments, ...props }) {
return comments.map(item => (
2021-04-28 19:30:14 +00:00
<Comment key={item.id} item={item} {...props} />
2021-04-27 00:55:48 +00:00
))
}
export function CommentsSkeleton () {
2021-04-28 22:52:03 +00:00
const comments = new Array(1).fill(null)
2021-04-27 00:55:48 +00:00
return comments.map((_, i) => (
2021-04-28 22:52:03 +00:00
<CommentSkeleton key={i} skeletonChildren={2} />
2021-04-27 00:55:48 +00:00
))
}
export function CommentsQuery ({ query, ...props }) {
2021-04-22 22:14:32 +00:00
const { loading, error, data } = useQuery(query)
2021-04-17 18:15:18 +00:00
2021-04-22 22:14:32 +00:00
if (error) return <div>Failed to load!</div>
if (loading) {
2021-04-27 00:55:48 +00:00
return <CommentsSkeleton />
2021-04-22 22:14:32 +00:00
}
2021-04-15 19:41:02 +00:00
2021-04-27 00:55:48 +00:00
return <Comments comments={data.comments} {...props} />
2021-04-15 19:41:02 +00:00
}