|
1 | | -import React, { Suspense } from "react"; |
| 1 | +import React, { Suspense, SuspenseList } from "react"; |
2 | 2 | import { Stack, Heading } from "@chakra-ui/core"; |
3 | 3 |
|
4 | 4 | import { PageWrapper } from "../components/PageWrapper"; |
5 | 5 | import { PostList, PostListPH } from "../components/PostList"; |
6 | 6 | import { PostDetail } from "../components/PostDetail"; |
| 7 | +import { CommentsList, CommentsListPH } from "../components/CommentsList"; |
7 | 8 |
|
8 | | -export default function Detail({ post, relatedPosts }) { |
| 9 | +export default function Detail({ post, relatedPosts, comments }) { |
9 | 10 | const postData = post.read(); |
10 | 11 |
|
11 | 12 | return ( |
12 | 13 | <PageWrapper> |
13 | 14 | <Stack spacing={4}> |
14 | 15 | <PostDetail post={postData} /> |
15 | | - <Suspense fallback={<RelatedPostsPH />}> |
16 | | - <RelatedPosts posts={relatedPosts} /> |
17 | | - </Suspense> |
| 16 | + <SuspenseList revealOrder="forwards"> |
| 17 | + <Suspense fallback={<CommentsPH />}> |
| 18 | + <Comments comments={comments} /> |
| 19 | + </Suspense> |
| 20 | + <Suspense fallback={<RelatedPostsPH />}> |
| 21 | + <RelatedPosts posts={relatedPosts} /> |
| 22 | + </Suspense> |
| 23 | + </SuspenseList> |
18 | 24 | </Stack> |
19 | 25 | </PageWrapper> |
20 | 26 | ); |
@@ -48,3 +54,33 @@ const RelatedPostsWrapper = ({ children, props }) => ( |
48 | 54 | {children} |
49 | 55 | </Stack> |
50 | 56 | ); |
| 57 | + |
| 58 | +// Comments |
| 59 | +const Comments = ({ comments }) => { |
| 60 | + const commentsData = comments.read(); |
| 61 | + return ( |
| 62 | + <CommentsWrapper> |
| 63 | + <CommentsList comments={commentsData} /> |
| 64 | + </CommentsWrapper> |
| 65 | + ); |
| 66 | +}; |
| 67 | + |
| 68 | +const CommentsPH = () => ( |
| 69 | + <CommentsWrapper> |
| 70 | + <CommentsListPH placeholders={3} /> |
| 71 | + </CommentsWrapper> |
| 72 | +); |
| 73 | + |
| 74 | +const CommentsWrapper = ({ children, props }) => ( |
| 75 | + <Stack spacing={8} mb={8}> |
| 76 | + <Heading |
| 77 | + size="md" |
| 78 | + pb={4} |
| 79 | + borderBottomWidth="1px" |
| 80 | + borderBottomColor="gray.200" |
| 81 | + > |
| 82 | + Comments |
| 83 | + </Heading> |
| 84 | + {children} |
| 85 | + </Stack> |
| 86 | +); |
0 commit comments