Skip to content

Commit ee781f7

Browse files
committed
patch:removed grey spinners with skeletons for CLS
1 parent 3a26029 commit ee781f7

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

src/components/PapersCarousel.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import { useEffect, useState } from "react";
44
import axios from "axios";
55
import { type IUpcomingPaper } from "@/interface";
6-
import Loader from "./ui/loader";
76
import UpcomingPaper from "./UpcomingPaper";
87
import {
98
Carousel,
@@ -14,6 +13,7 @@ import {
1413
} from "@/components/ui/carousel";
1514
import Autoplay from "embla-carousel-autoplay";
1615
import { chunkArray } from "@/util/utils";
16+
import { Skeleton } from "@/components/ui/skeleton";
1717

1818
function PapersCarousel({
1919
carouselType,
@@ -41,7 +41,7 @@ function PapersCarousel({
4141
"Design and Analysis of Algorithms [MCSE502L]",
4242
"Complex Variables and Linear Algebra [BMAT201L]",
4343
"Differential Equations and Transforms [BMAT102L]",
44-
]),
44+
])
4545
);
4646

4747
handleResize();
@@ -62,11 +62,14 @@ function PapersCarousel({
6262
const storedSubjects = JSON.parse(
6363
localStorage.getItem("userSubjects") ?? "[]"
6464
) as string[];
65-
const response = await axios.post<IUpcomingPaper []>("/api/user-papers", storedSubjects);
65+
const response = await axios.post<IUpcomingPaper[]>(
66+
"/api/user-papers",
67+
storedSubjects
68+
);
6669
setDisplayPapers(response.data);
6770
} else {
6871
const response = await axios.get<IUpcomingPaper[]>(
69-
"/api/upcoming-papers",
72+
"/api/upcoming-papers"
7073
);
7174
setDisplayPapers(response.data);
7275
}
@@ -81,7 +84,23 @@ function PapersCarousel({
8184
}, []);
8285

8386
if (isLoading) {
84-
return <Loader prop="m-10" />;
87+
return (
88+
<div className="px-4">
89+
<p className="my-8 text-center font-play text-lg font-semibold">
90+
{carouselType === "users" ? "Your Papers" : "Upcoming Papers"}
91+
</p>
92+
93+
<div className="grid grid-cols-2 grid-rows-2 gap-4 md:grid-cols-4 lg:auto-rows-fr">
94+
{Array.from({ length: 8 }).map((_, index) => (
95+
<div key={index} className="space-y-4 p-2">
96+
<Skeleton className="h-4 w-[70%]" />
97+
<Skeleton className="h-4 w-[50%]" />
98+
<Skeleton className="h-20 w-full rounded-lg" />
99+
</div>
100+
))}
101+
</div>
102+
</div>
103+
);
85104
}
86105

87106
const plugins = [Autoplay({ delay: 8000, stopOnInteraction: true })];

src/components/ui/skeleton.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { cn } from "@/lib/utils"
2+
3+
function Skeleton({
4+
className,
5+
...props
6+
}: React.HTMLAttributes<HTMLDivElement>) {
7+
return (
8+
<div
9+
className={cn("animate-pulse rounded-md bg-primary/10", className)}
10+
{...props}
11+
/>
12+
)
13+
}
14+
15+
export { Skeleton }

0 commit comments

Comments
 (0)