Skip to content

Commit 9585c1e

Browse files
committed
feat: comment skeleton
Signed-off-by: Innei <[email protected]>
1 parent ebd4ed1 commit 9585c1e

File tree

3 files changed

+43
-17
lines changed

3 files changed

+43
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,40 @@
1-
import { clsxm } from '~/utils/helper'
2-
3-
export const CommentSkeleton: Component = ({ className }) => {
1+
const CommentSkeletonSingle = () => {
42
return (
5-
<div className={clsxm('flex animate-pulse flex-col gap-3', className)}>
6-
<div className="h-6 w-full rounded-lg bg-gray-200 dark:bg-zinc-800/80" />
7-
<div className="h-6 w-full rounded-lg bg-gray-200 dark:bg-zinc-800/80" />
8-
<div className="h-6 w-full rounded-lg bg-gray-200 dark:bg-zinc-800/80" />
9-
<div className="h-6 w-full rounded-lg bg-gray-200 dark:bg-zinc-800/80" />
3+
<li className="relative animate-pulse list-none">
4+
<div className="group flex w-full items-stretch gap-2">
5+
<div className="flex w-9 shrink-0 items-end">
6+
<div className="h-9 w-9 rounded-full bg-gray-300 dark:bg-neutral-600" />
7+
</div>
8+
9+
<div className="flex w-full min-w-0 flex-1 flex-col items-start">
10+
<span className="relative mb-2 flex w-full min-w-0 items-center justify-center gap-2">
11+
<span className="flex flex-grow items-center gap-2">
12+
<span className="ml-2 h-4 w-20 bg-gray-300 dark:bg-neutral-600" />
13+
<span className="flex select-none items-center space-x-2">
14+
<span className="inline-flex h-4 w-20 bg-gray-300 text-[10px] font-medium opacity-40 dark:bg-neutral-600" />
15+
<span className="h-4 w-20 bg-gray-300 text-[10px] opacity-30 dark:bg-neutral-600" />
16+
</span>
17+
</span>
18+
</span>
19+
20+
<div className="relative flex w-full flex-col gap-2">
21+
<div className="relative ml-2 inline-block h-4 w-[calc(100%-3rem)] rounded-xl bg-gray-300 px-2 py-1 dark:bg-neutral-600" />
22+
<div className="relative ml-2 inline-block h-4 w-[120px] rounded-xl bg-gray-300 px-2 py-1 dark:bg-neutral-600" />
23+
</div>
24+
</div>
25+
</div>
26+
1027
<span className="sr-only">Loading...</span>
28+
</li>
29+
)
30+
}
31+
export const CommentSkeleton: Component = () => {
32+
return (
33+
<div className="flex flex-col space-y-4">
34+
<CommentSkeletonSingle />
35+
<CommentSkeletonSingle />
36+
<CommentSkeletonSingle />
37+
<CommentSkeletonSingle />
1138
</div>
1239
)
1340
}

src/components/widgets/comment/Comments.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ export const Comments: FC<CommentBaseProps> = ({ refId }) => {
6060
}),
6161
)}
6262
</ul>
63-
{hasNextPage && <LoadMoreIndicator onClick={fetchNextPage} />}
63+
{hasNextPage && (
64+
<LoadMoreIndicator onClick={fetchNextPage}>
65+
<CommentSkeleton />
66+
</LoadMoreIndicator>
67+
)}
6468
</>
6569
)
6670
}
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
'use client'
22

33
import { useInView } from 'react-intersection-observer'
4-
import type { FC } from 'react'
54

65
import { Loading } from '~/components/ui/loading'
76

8-
export const LoadMoreIndicator: FC<{
7+
export const LoadMoreIndicator: Component<{
98
onClick: () => void
10-
}> = ({ onClick }) => {
9+
}> = ({ onClick, children }) => {
1110
const { ref } = useInView({
1211
rootMargin: '1px',
1312
onChange(inView) {
1413
if (inView) onClick()
1514
},
1615
})
17-
return (
18-
<div ref={ref}>
19-
<Loading />
20-
</div>
21-
)
16+
return <div ref={ref}>{children ?? <Loading />}</div>
2217
}

0 commit comments

Comments
 (0)