Skip to content

Commit 349fa6c

Browse files
committed
feat: add spin loader while scrolling
1 parent f2a7038 commit 349fa6c

File tree

6 files changed

+58
-5
lines changed

6 files changed

+58
-5
lines changed

apps/web/@/molecules/post-list/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { useCallback, useState } from "react"
44
import { useSearchParams } from "next/navigation"
55

66
import { getPosts, PostStatus, TPostItem } from "database"
7+
import { Loader } from "lucide-react"
8+
import { PostSkeleton } from "ui"
79

810
import useInfiniteScroll from "@/hooks/useInfinityScroll"
911

@@ -47,7 +49,11 @@ export default function PostList({ containerClassName }: PostListProps) {
4749
ref={setNode}
4850
className="h-10 w-full"
4951
>
50-
{loading && <div>Loading...</div>}
52+
{loading && (
53+
<div className="flex min-h-10 items-center justify-center">
54+
<Loader className="animate-spin" />
55+
</div>
56+
)}
5157
</div>
5258
</div>
5359
)

apps/web/@/molecules/posts/post-item/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import APP_ROUTES from "@/constants/routes"
99
import TagList from "@/molecules/tag/tag-list"
1010
import { generatePath } from "@/utils/generatePath"
1111

12-
import BookmarkButton from "./bookmark-button"
1312
import CommentButton from "./comment-button"
1413
import LikeButton from "./like-button"
1514
import PostMeta from "./post-meta"
@@ -49,10 +48,10 @@ export default function PostItem({ post }: { post: TPostItem }) {
4948
</div>
5049
</div>
5150
</div>
52-
{post.Image && (
51+
{post.image && (
5352
<div className="flex items-center">
5453
<Image
55-
src={post.Image.url}
54+
src={post.image.previewUrl}
5655
alt={post.title}
5756
width={160}
5857
height={120}

apps/web/app/[lang]/(public)/page.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import { Suspense } from "react"
12
import { Metadata } from "next"
23

4+
import { PostSkeleton } from "ui"
5+
36
import Filter from "@/molecules/home/filter"
47
import PostList from "@/molecules/post-list"
58

@@ -12,7 +15,9 @@ export default async function Page() {
1215
return (
1316
<div>
1417
<Filter />
15-
<PostList containerClassName="mt-4" />
18+
<Suspense fallback={<PostSkeleton total={10} />}>
19+
<PostList containerClassName="mt-4" />
20+
</Suspense>
1621
</div>
1722
)
1823
}

packages/database/src/posts/selects.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const postSelect = {
1414
select: {
1515
id: true,
1616
url: true,
17+
previewUrl: true,
1718
},
1819
},
1920
author: {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import * as React from "react"
2+
3+
import { Skeleton } from "../../components/ui/skeleton"
4+
import { cn } from "../../lib/utils"
5+
6+
interface PostSkeletonProps extends React.HTMLAttributes<HTMLDivElement> {
7+
total?: number
8+
containerClassName?: string
9+
}
10+
11+
function PostSkeleton({
12+
total = 1,
13+
className,
14+
containerClassName = "",
15+
...props
16+
}: PostSkeletonProps) {
17+
return (
18+
<div className={cn("flex flex-col gap-4", containerClassName)}>
19+
{Array.from({ length: total }).map((_, index) => (
20+
<div
21+
className={cn("flex gap-4", className)}
22+
{...props}
23+
key={index}
24+
>
25+
<div className="flex flex-1 flex-col items-start gap-4">
26+
<Skeleton className="h-10 w-full" />
27+
<Skeleton className="h-4 w-[50%]" />
28+
<div className="flex items-center space-x-2">
29+
<Skeleton className="h-4 w-[100px]" />
30+
<Skeleton className="h-4 w-[100px]" />
31+
</div>
32+
</div>
33+
<Skeleton className="h-[100px] w-[160px]" />
34+
</div>
35+
))}
36+
</div>
37+
)
38+
}
39+
40+
export { PostSkeleton }

packages/ui/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,5 @@ export {
230230
export { cn } from "././@/lib/utils"
231231

232232
export { LoadingButton } from "./@/components/ui/loading-button"
233+
234+
export { PostSkeleton } from "./@/molecules/skeleton/posts"

0 commit comments

Comments
 (0)