@@ -23,6 +23,7 @@ import PinnedModal from "./ui/PinnedModal";
2323type PinnedPapersCarouselProps = {
2424 carouselType : "users" | "upcoming" ,
2525}
26+ import { Plus } from "lucide-react" ;
2627
2728function PinnedPapersCarousel ( {
2829 carouselType = "upcoming" ,
@@ -49,6 +50,18 @@ function PinnedPapersCarousel({
4950
5051 const chunkedPapers = chunkArray ( displayPapers , chunkSize ) ;
5152
53+ if ( chunkedPapers . length > 0 ) {
54+ const lastChunkIndex = chunkedPapers . length - 1 ;
55+ if ( ( chunkedPapers [ lastChunkIndex ] ?. length ?? 0 ) < chunkSize ) {
56+ chunkedPapers [ lastChunkIndex ] = [
57+ ...( chunkedPapers [ lastChunkIndex ] ?? [ ] ) ,
58+ { subject : "add_subject_button" , slots : [ ] } as IUpcomingPaper ,
59+ ] ;
60+ } else {
61+ chunkedPapers . push ( [ { subject : "add_subject_button" , slots : [ ] } as IUpcomingPaper ] ) ;
62+ }
63+ }
64+
5265 const fetchPapers = async ( ) => {
5366 try {
5467 setIsLoading ( true ) ;
@@ -138,7 +151,7 @@ function PinnedPapersCarousel({
138151 const plugins = [ Autoplay ( { delay : 8000 , stopOnInteraction : true } ) ] ;
139152
140153 return (
141- < div className = "px-4 mt-4" >
154+ < div className = "px-4 mt-8 md:mt- 4" >
142155 < div className = "" >
143156 { displayPapers . length > 0 ?
144157 < Carousel
@@ -149,7 +162,7 @@ function PinnedPapersCarousel({
149162 plugins = { plugins }
150163 className = "w-full"
151164 >
152- { displayPapers . length > 8 &&
165+ { displayPapers . length >= 8 &&
153166 < div
154167 className = { `relative mt-4 flex justify-end gap-4` }
155168 >
@@ -167,8 +180,7 @@ function PinnedPapersCarousel({
167180 </ CarouselItem >
168181 ) : (
169182 chunkedPapers . map ( ( paperGroup , index ) => {
170- const isLastChunk = index === chunkedPapers . length - 1 ;
171-
183+ const placeholdersNeeded = ( chunkSize - paperGroup . length ) % chunkSize ;
172184 return (
173185 < CarouselItem
174186 key = { `carousel-item-${ index } ` }
@@ -177,6 +189,11 @@ function PinnedPapersCarousel({
177189 } gap-4 lg:auto-rows-fr`}
178190 >
179191 { paperGroup . map ( ( paper , subIndex ) => (
192+ paper . subject === "add_subject_button" ?
193+ < div key = { subIndex } className = "h-full border-dashed border border-[#734DFF] dark:border-[#36266D] rounded-sm font-bold hover:bg-[#EFEAFF] dark:bg-transparent dark:hover:bg-[#1A1823] bg-[#FFFFFF]" >
194+ < PinnedModal triggerName = { "Add Subjects" } page = { "Carousel" } />
195+ </ div >
196+ :
180197 < div key = { subIndex } className = "h-full" >
181198 < UpcomingPaper
182199 subject = { paper . subject }
@@ -185,26 +202,24 @@ function PinnedPapersCarousel({
185202 </ div >
186203 ) ) }
187204
188- { isLastChunk && displayPapers . length < 8 && (
205+ { Array . from ( { length : placeholdersNeeded } ) . map (
206+ ( _ , placeholderIndex ) => (
189207 < div
190- className = "h-full"
191- onClick = { ( ) => {
192- window . dispatchEvent ( new Event ( "addButtonClicked" ) ) ;
193- } }
194- >
195- </ div >
196- ) }
208+ key = { `placeholder-${ placeholderIndex } ` }
209+ className = "invisible h-full"
210+ > </ div >
211+ ) ,
212+ ) }
197213 </ CarouselItem >
198214 ) ;
199215 } )
200216 ) }
201217 </ CarouselContent >
202218 </ Carousel > :
203- < div className = { `relative flex flex-col justify-center gap-4 items-center h-max text-center my-48 font-bold` }
219+ < div className = { `relative flex flex-col justify-center gap-4 items-center text-center font-bold` }
204220 >
205221 Start pinning subjects for quick and easy access.
206222 < div className = "flex h-8 items-center gap-1 rounded-full border border-[#3A3745] bg-[#e8e9ff] px-2.5 py-1 text-xs font-semibold text-gray-700 transition hover:bg-slate-50 dark:bg-black dark:text-white dark:hover:bg-[#1A1823] sm:h-9 sm:gap-2 sm:px-3.5 sm:py-1.5 sm:text-sm md:h-10 md:px-4 md:py-2 md:text-base" >
207- < Pin className = "h-3.5 w-3.5 sm:h-4 sm:w-4" />
208223 < span className = "truncate" >
209224 < PinnedModal />
210225 </ span >
0 commit comments