Skip to content

Commit bbc6785

Browse files
authored
Merge pull request #408 from sankalp771/fix-arrow-navigation-399
fix: hide arrow buttons
2 parents c7e4f26 + 646dab9 commit bbc6785

File tree

1 file changed

+58
-55
lines changed

1 file changed

+58
-55
lines changed

src/components/PapersCarousel.tsx

Lines changed: 58 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -63,66 +63,69 @@ function PapersCarousel() {
6363
const plugins = [Autoplay({ delay: 8000, stopOnInteraction: true })];
6464

6565
return (
66-
<div className="mt-3 px-4">
67-
<p className="my-8 hidden text-center font-play text-lg font-semibold md:block">
68-
Upcoming Exams
69-
</p>
66+
<div className="mt-3 px-4">
67+
<p className="my-8 hidden text-center font-play text-lg font-semibold md:block">
68+
Upcoming Exams
69+
</p>
7070

71-
<Carousel
72-
opts={{ align: "start", loop: true }}
73-
plugins={plugins}
74-
className="w-full"
75-
>
76-
<div className="relative mt-4 flex justify-end gap-4">
77-
<CarouselPrevious className="relative" />
78-
<CarouselNext className="relative" />
79-
</div>
80-
81-
<CarouselContent>
82-
{isLoading ? (
83-
<CarouselItem
84-
className={`grid ${
85-
chunkSize === 2 ? "grid-cols-1 grid-rows-2" : chunkSize === 4 ? "grid-cols-2 grid-rows-2" : "grid-cols-4"
86-
} gap-4 lg:auto-rows-fr`}
87-
>
88-
<SkeletonPaperCard length={chunkSize} />
89-
</CarouselItem>
90-
) : (
91-
chunkedPapers.map((paperGroup, index) => {
92-
const placeholdersNeeded = chunkSize - paperGroup.length;
71+
<Carousel
72+
opts={{ align: "start", loop: true }}
73+
plugins={plugins}
74+
className="w-full"
75+
>
76+
{/* Only show arrows when there are multiple chunks to scroll through */}
77+
{chunkedPapers.length > 1 && displayPapers.length > chunkSize && (
78+
<div className="relative mt-4 flex justify-end gap-4">
79+
<CarouselPrevious className="relative" />
80+
<CarouselNext className="relative" />
81+
</div>
82+
)}
9383

94-
return (
84+
<CarouselContent>
85+
{isLoading ? (
9586
<CarouselItem
96-
key={`carousel-item-${index}`}
97-
className={`grid ${
98-
chunkSize === 2 ? "grid-cols-1 grid-rows-2" : chunkSize === 4 ? "grid-cols-2 grid-rows-2" : "grid-cols-4"
99-
} gap-4 lg:auto-rows-fr`}
87+
className={`grid ${
88+
chunkSize === 2 ? "grid-cols-1 grid-rows-2" : chunkSize === 4 ? "grid-cols-2 grid-rows-2" : "grid-cols-4"
89+
} gap-4 lg:auto-rows-fr`}
10090
>
101-
{paperGroup.map((paper, subIndex) => (
102-
<div key={subIndex} className="h-full">
103-
<UpcomingPaper
104-
subject={paper.subject}
105-
slots={paper.slots}
106-
/>
107-
</div>
108-
))}
109-
110-
{Array.from({ length: placeholdersNeeded }).map(
111-
(_, placeholderIndex) => (
112-
<div
113-
key={`placeholder-${placeholderIndex}`}
114-
className="invisible h-full"
115-
></div>
116-
),
117-
)}
91+
<SkeletonPaperCard length={chunkSize} />
11892
</CarouselItem>
119-
);
120-
})
121-
)}
122-
</CarouselContent>
123-
</Carousel>
124-
</div>
93+
) : (
94+
chunkedPapers.map((paperGroup, index) => {
95+
const placeholdersNeeded = chunkSize - paperGroup.length;
96+
97+
return (
98+
<CarouselItem
99+
key={`carousel-item-${index}`}
100+
className={`grid ${
101+
chunkSize === 2 ? "grid-cols-1 grid-rows-2" : chunkSize === 4 ? "grid-cols-2 grid-rows-2" : "grid-cols-4"
102+
} gap-4 lg:auto-rows-fr`}
103+
>
104+
{paperGroup.map((paper, subIndex) => (
105+
<div key={subIndex} className="h-full">
106+
<UpcomingPaper
107+
subject={paper.subject}
108+
slots={paper.slots}
109+
/>
110+
</div>
111+
))}
112+
113+
{Array.from({ length: placeholdersNeeded }).map(
114+
(_, placeholderIndex) => (
115+
<div
116+
key={`placeholder-${placeholderIndex}`}
117+
className="invisible h-full"
118+
></div>
119+
),
120+
)}
121+
</CarouselItem>
122+
);
123+
})
124+
)}
125+
</CarouselContent>
126+
</Carousel>
127+
</div>
125128
);
126129
}
127130

128-
export default PapersCarousel;
131+
export default PapersCarousel;

0 commit comments

Comments
 (0)