-
Notifications
You must be signed in to change notification settings - Fork 153
/
item.js
45 lines (40 loc) · 1 KB
/
item.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Suspense } from 'react';
import Story from './story';
import Comment from './comment';
import CommentForm from './comment-form';
import getComments from '../lib/get-comments';
import Skeletons from './skeletons';
import styles from './item.module.css';
async function Comments({ story }) {
if (!story) {
return <div className={styles.loading}>No Comments</div>;
}
const comments = await getComments(story.comments);
return (
<div className={styles.comments}>
{(comments || []).map((comment) => (
<Comment key={comment.id} {...comment} />
))}
</div>
);
}
export default function Item({ story }) {
return (
<div className={styles.item}>
<Story {...story} />
<div className={styles.form}>
<CommentForm />
</div>
<Suspense
fallback={
<div>
{`Loading comments...`}
<Skeletons count={3} />
</div>
}
>
<Comments story={story} />
</Suspense>
</div>
);
}