Skip to content

Commit d26e0f8

Browse files
committed
fix: responsiveness for carousel
1 parent 4ea8746 commit d26e0f8

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

src/components/PapersCarousel.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ function PapersCarousel() {
2323

2424
useEffect(() => {
2525
const handleResize = () => {
26-
if (window.innerWidth < 640) {
26+
if(window.innerWidth <= 540){
27+
setChunkSize(2);
28+
}
29+
else if (window.innerWidth <= 920) {
2730
setChunkSize(4);
2831
} else {
2932
setChunkSize(8);
@@ -76,7 +79,7 @@ function PapersCarousel() {
7679
{isLoading ? (
7780
<CarouselItem
7881
className={`grid ${
79-
chunkSize === 4 ? "grid-cols-2 grid-rows-2" : "grid-cols-4"
82+
chunkSize === 2 ? "grid-cols-1 grid-rows-2" : chunkSize === 4 ? "grid-cols-2 grid-rows-2" : "grid-cols-4"
8083
} gap-4 lg:auto-rows-fr`}
8184
>
8285
<SkeletonPaperCard length={chunkSize} />
@@ -89,9 +92,7 @@ function PapersCarousel() {
8992
<CarouselItem
9093
key={`carousel-item-${index}`}
9194
className={`grid ${
92-
chunkSize === 4
93-
? "grid-cols-2 grid-rows-2"
94-
: "grid-cols-4 grid-rows-2"
95+
chunkSize === 2 ? "grid-cols-1 grid-rows-2" : chunkSize === 4 ? "grid-cols-2 grid-rows-2" : "grid-cols-4"
9596
} gap-4 lg:auto-rows-fr`}
9697
>
9798
{paperGroup.map((paper, subIndex) => (

src/components/PinnedPapersCarousel.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ function PinnedPapersCarousel({
3535

3636
useEffect(() => {
3737
const handleResize = () => {
38-
if (window.innerWidth < 640) {
38+
if(window.innerWidth <= 540){
39+
setChunkSize(2);
40+
}
41+
else if (window.innerWidth <= 920) {
3942
setChunkSize(4);
4043
} else {
4144
setChunkSize(8);
4245
}
4346
};
4447

45-
handleResize();
48+
handleResize(); // initialize
4649
window.addEventListener("resize", handleResize);
47-
48-
return () => {
49-
window.removeEventListener("resize", handleResize);
50-
};
50+
return () => window.removeEventListener("resize", handleResize);
5151
}, []);
5252

5353
const chunkedPapers = chunkArray(displayPapers, chunkSize);
@@ -110,7 +110,7 @@ function PinnedPapersCarousel({
110110
const plugins = [Autoplay({ delay: 8000, stopOnInteraction: true })];
111111

112112
return (
113-
<div className="px-4 sm:mt-4">
113+
<div className="px-4 mt-4">
114114
<div className="">
115115
{displayPapers.length > 0 ?
116116
<Carousel
@@ -132,7 +132,7 @@ function PinnedPapersCarousel({
132132
{isLoading ? (
133133
<CarouselItem
134134
className={`grid ${
135-
chunkSize === 4 ? "grid-cols-2 grid-rows-2" : "grid-cols-4"
135+
chunkSize === 2 ? "grid-cols-1 grid-rows-2" : chunkSize === 4 ? "grid-cols-2 grid-rows-2" : "grid-cols-4"
136136
} gap-4 lg:auto-rows-fr`}
137137
>
138138
<SkeletonPaperCard length={chunkSize} />
@@ -145,9 +145,7 @@ function PinnedPapersCarousel({
145145
<CarouselItem
146146
key={`carousel-item-${index}`}
147147
className={`grid ${
148-
chunkSize === 4
149-
? "grid-cols-2 grid-rows-2"
150-
: "grid-cols-4"
148+
chunkSize === 2 ? "grid-cols-1 grid-rows-2" : chunkSize === 4 ? "grid-cols-2 grid-rows-2" : "grid-cols-4"
151149
} gap-4 lg:auto-rows-fr`}
152150
>
153151
{paperGroup.map((paper, subIndex) => (
@@ -175,7 +173,7 @@ function PinnedPapersCarousel({
175173
)}
176174
</CarouselContent>
177175
</Carousel> :
178-
<div className={`relative flex justify-center gap-4 items-center h-max text-center mt-48 font-bold`}
176+
<div className={`relative flex justify-center gap-4 items-center h-max text-center my-48 font-bold`}
179177
>
180178
Start pinning subjects for quick and easy access.
181179
</div>}

0 commit comments

Comments
 (0)