Skip to content

Commit 408ed1e

Browse files
authored
Merge pull request #499 from atharvaSharma17/fix3
fix carousel grid
2 parents 28199ce + 1209a71 commit 408ed1e

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/components/PinnedPapersCarousel.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,18 +199,19 @@ function PinnedPapersCarousel() {
199199
</CarouselItem>
200200
) : (
201201
chunkedPapers.map((paperGroup, index) => {
202-
const placeholdersNeeded =
203-
(chunkSize - paperGroup.length) % chunkSize;
202+
const columns = chunkSize === 2 ? 1 : chunkSize === 4 ? 2 : 4;
203+
const rows = Math.max(1, Math.ceil(paperGroup.length / columns));
204+
const placeholdersNeeded = columns * rows - paperGroup.length;
204205
return (
205206
<CarouselItem
206207
key={`carousel-item-${index}`}
207208
className={`grid ${
208-
chunkSize === 2
209-
? "grid-cols-1 grid-rows-2"
210-
: chunkSize === 4
211-
? "grid-cols-2 grid-rows-2"
209+
columns === 1
210+
? "grid-cols-1"
211+
: columns === 2
212+
? "grid-cols-2"
212213
: "grid-cols-4"
213-
} gap-4 lg:auto-rows-fr`}
214+
} ${rows === 1 ? "grid-rows-1" : "grid-rows-2"} gap-4 lg:auto-rows-fr`}
214215
>
215216
{paperGroup.map((paper, subIndex) =>
216217
paper.subject === "add_subject_button" ? (
@@ -264,4 +265,4 @@ function PinnedPapersCarousel() {
264265
);
265266
}
266267

267-
export default PinnedPapersCarousel;
268+
export default PinnedPapersCarousel;

0 commit comments

Comments
 (0)