File tree Expand file tree Collapse file tree 6 files changed +58
-5
lines changed
Expand file tree Collapse file tree 6 files changed +58
-5
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ import { useCallback, useState } from "react"
44import { useSearchParams } from "next/navigation"
55
66import { getPosts , PostStatus , TPostItem } from "database"
7+ import { Loader } from "lucide-react"
8+ import { PostSkeleton } from "ui"
79
810import 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 )
Original file line number Diff line number Diff line change @@ -9,7 +9,6 @@ import APP_ROUTES from "@/constants/routes"
99import TagList from "@/molecules/tag/tag-list"
1010import { generatePath } from "@/utils/generatePath"
1111
12- import BookmarkButton from "./bookmark-button"
1312import CommentButton from "./comment-button"
1413import LikeButton from "./like-button"
1514import 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 }
Original file line number Diff line number Diff line change 1+ import { Suspense } from "react"
12import { Metadata } from "next"
23
4+ import { PostSkeleton } from "ui"
5+
36import Filter from "@/molecules/home/filter"
47import 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}
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ export const postSelect = {
1414 select : {
1515 id : true ,
1616 url : true ,
17+ previewUrl : true ,
1718 } ,
1819 } ,
1920 author : {
Original file line number Diff line number Diff line change 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 }
Original file line number Diff line number Diff line change @@ -230,3 +230,5 @@ export {
230230export { cn } from "././@/lib/utils"
231231
232232export { LoadingButton } from "./@/components/ui/loading-button"
233+
234+ export { PostSkeleton } from "./@/molecules/skeleton/posts"
You can’t perform that action at this time.
0 commit comments