@@ -23,10 +23,9 @@ function PapersCarousel() {
2323
2424 useEffect ( ( ) => {
2525 const handleResize = ( ) => {
26- if ( window . innerWidth <= 540 ) {
26+ if ( window . innerWidth <= 540 ) {
2727 setChunkSize ( 2 ) ;
28- }
29- else if ( window . innerWidth <= 920 ) {
28+ } else if ( window . innerWidth <= 920 ) {
3029 setChunkSize ( 4 ) ;
3130 } else {
3231 setChunkSize ( 8 ) ;
@@ -42,7 +41,9 @@ function PapersCarousel() {
4241 const fetchPapers = async ( ) => {
4342 try {
4443 setIsLoading ( true ) ;
45- const response = await axios . get < IUpcomingPaper [ ] > ( "/api/upcoming-papers" ) ;
44+ const response = await axios . get < IUpcomingPaper [ ] > (
45+ "/api/upcoming-papers" ,
46+ ) ;
4647 setDisplayPapers ( response . data ) ;
4748 } catch ( error ) {
4849 console . error ( "Failed to fetch papers:" , error ) ;
@@ -62,70 +63,90 @@ function PapersCarousel() {
6263 const chunkedPapers = chunkArray ( displayPapers , chunkSize ) ;
6364 const plugins = [ Autoplay ( { delay : 8000 , stopOnInteraction : true } ) ] ;
6465
65- return (
66+ if ( chunkedPapers . length === 0 )
67+ return (
6668 < div className = "mt-3 px-4" >
6769 < p className = "my-8 text-center font-play text-lg font-semibold md:block" >
6870 Upcoming Exams
6971 </ p >
72+ < p className = "my-8 text-center font-play text-lg font-semibold md:block" >
73+ < i > No more upcoming papers, Enjoy your break!</ i >
74+ </ p >
75+ </ div >
76+ ) ;
7077
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- ) }
78+ return (
79+ < div className = "mt-3 px-4" >
80+ < p className = "my-8 text-center font-play text-lg font-semibold md:block" >
81+ Upcoming Exams
82+ </ p >
8383
84- < CarouselContent >
85- { isLoading ? (
84+ < Carousel
85+ opts = { { align : "start" , loop : true } }
86+ plugins = { plugins }
87+ className = "w-full"
88+ >
89+ { /* Only show arrows when there are multiple chunks to scroll through */ }
90+ { chunkedPapers . length > 1 && displayPapers . length > chunkSize && (
91+ < div className = "relative mt-4 flex justify-end gap-4" >
92+ < CarouselPrevious className = "relative" />
93+ < CarouselNext className = "relative" />
94+ </ div >
95+ ) }
96+
97+ < CarouselContent >
98+ { isLoading ? (
99+ < CarouselItem
100+ className = { `grid ${
101+ chunkSize === 2
102+ ? "grid-cols-1 grid-rows-2"
103+ : chunkSize === 4
104+ ? "grid-cols-2 grid-rows-2"
105+ : "grid-cols-4"
106+ } gap-4 lg:auto-rows-fr`}
107+ >
108+ < SkeletonPaperCard length = { chunkSize } />
109+ </ CarouselItem >
110+ ) : (
111+ chunkedPapers . map ( ( paperGroup , index ) => {
112+ const placeholdersNeeded = chunkSize - paperGroup . length ;
113+
114+ return (
86115 < CarouselItem
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`}
116+ key = { `carousel-item-${ index } ` }
117+ className = { `grid ${
118+ chunkSize === 2
119+ ? "grid-cols-1 grid-rows-2"
120+ : chunkSize === 4
121+ ? "grid-cols-2 grid-rows-2"
122+ : "grid-cols-4"
123+ } gap-4 lg:auto-rows-fr`}
90124 >
91- < SkeletonPaperCard length = { chunkSize } />
92- </ CarouselItem >
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- ) ) }
125+ { paperGroup . map ( ( paper , subIndex ) => (
126+ < div key = { subIndex } className = "h-full" >
127+ < UpcomingPaper
128+ subject = { paper . subject }
129+ slots = { paper . slots }
130+ />
131+ </ div >
132+ ) ) }
112133
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 >
134+ { Array . from ( { length : placeholdersNeeded } ) . map (
135+ ( _ , placeholderIndex ) => (
136+ < div
137+ key = { `placeholder-${ placeholderIndex } ` }
138+ className = "invisible h-full"
139+ > </ div >
140+ ) ,
141+ ) }
142+ </ CarouselItem >
143+ ) ;
144+ } )
145+ ) }
146+ </ CarouselContent >
147+ </ Carousel >
148+ </ div >
128149 ) ;
129150}
130151
131- export default PapersCarousel ;
152+ export default PapersCarousel ;
0 commit comments