1
1
"use client"
2
2
3
- import { useRef , useState } from "react"
4
- import { SwiperRef } from "swiper/react"
3
+ import { useEffect , useState } from "react"
5
4
6
- import { ChevronNext , ChevronPrev } from "@/components/Chevron"
7
- import { Image } from "@/components/Image"
8
- import { Button , ButtonLink } from "@/components/ui/buttons/Button"
9
- import { Swiper , SwiperContainer , SwiperSlide } from "@/components/ui/swiper"
10
-
11
- import { cn } from "@/lib/utils/cn"
5
+ // import { Image } from "@/components/Image"
6
+ import {
7
+ Carousel ,
8
+ type CarouselApi ,
9
+ CarouselContent ,
10
+ CarouselItem ,
11
+ CarouselNext ,
12
+ CarouselPrevious ,
13
+ } from "@/components/ui/carousel"
12
14
15
+ // import { cn } from "@/lib/utils/cn"
13
16
import { releasesData } from "@/data/roadmap/releases"
14
17
15
- const formatReleaseDate = ( date : string ) => {
16
- if ( / ^ \d { 4 } $ / . test ( date ) ) {
17
- return date
18
- }
19
- return new Date ( date ) . toLocaleDateString ( "en-US" , {
20
- month : "long" ,
21
- day : "numeric" ,
22
- year : "numeric" ,
23
- } )
24
- }
18
+ // const formatReleaseDate = (date: string) => {
19
+ // if (/^\d{4}$/.test(date)) {
20
+ // return date
21
+ // }
22
+ // return new Date(date).toLocaleDateString("en-US", {
23
+ // month: "long",
24
+ // day: "numeric",
25
+ // year: "numeric",
26
+ // })
27
+ // }
25
28
26
29
const findLatestReleaseIndex = ( ) => {
27
30
const today = new Date ( )
@@ -51,62 +54,115 @@ const findLatestReleaseIndex = () => {
51
54
}
52
55
53
56
const ReleaseCarousel = ( ) => {
54
- const swiperRef = useRef < SwiperRef > ( null )
55
- const swiperRef2 = useRef < SwiperRef > ( null )
56
- const containerRef = useRef < HTMLDivElement > ( null )
57
- const containerRef2 = useRef < HTMLDivElement > ( null )
58
- const [ activeSlide , setActiveSlide ] = useState ( findLatestReleaseIndex ( ) )
59
- const pastReleases = releasesData . filter (
60
- ( release ) => release . releaseDate < new Date ( ) . toISOString ( ) . split ( "T" ) [ 0 ]
61
- )
57
+ const [ api1 , setApi1 ] = useState < CarouselApi > ( )
58
+ const [ api2 , setApi2 ] = useState < CarouselApi > ( )
62
59
63
- const PreviousButton = ( ) => {
64
- return (
65
- < Button
66
- variant = { "outline" }
67
- size = "xs"
68
- className = "h-8 w-8 rounded-full"
69
- onClick = { ( ) => {
70
- swiperRef . current ?. swiper . slidePrev ( )
71
- swiperRef2 . current ?. swiper . slidePrev ( )
72
- } }
73
- disabled = { activeSlide === 0 }
74
- >
75
- < ChevronPrev className = "h-8 w-8" />
76
- </ Button >
77
- )
78
- }
60
+ useEffect ( ( ) => {
61
+ if ( ! api1 || ! api2 ) {
62
+ return
63
+ }
79
64
80
- const NextButton = ( ) => {
81
- return (
82
- < Button
83
- variant = { "outline" }
84
- size = "xs"
85
- className = "h-8 w-8 rounded-full"
86
- onClick = { ( ) => {
87
- swiperRef . current ?. swiper . slideNext ( )
88
- swiperRef2 . current ?. swiper . slideNext ( )
89
- } }
90
- disabled = { activeSlide === releasesData . length - 1 }
91
- >
92
- < ChevronNext className = "h-8 w-8" />
93
- </ Button >
94
- )
95
- }
65
+ api1 . on ( "select" , ( ) => {
66
+ api2 . scrollTo ( api1 . selectedScrollSnap ( ) )
67
+ } )
68
+
69
+ api2 . on ( "select" , ( ) => {
70
+ api1 . scrollTo ( api2 . selectedScrollSnap ( ) )
71
+ } )
72
+ } , [ api1 , api2 ] )
96
73
97
74
return (
98
- < div className = "flex w-full flex-col gap-6 rounded-2xl bg-background-highlight p-6" >
99
- < div className = "flex w-full flex-row items-center justify-between gap-2" >
75
+ < div className = "w-full max-w-[100vw] overflow-hidden" >
76
+ < div className = "mx-auto w-full max-w-screen-2xl px-4 sm:px-6" >
77
+ < div className = "w-full rounded-2xl bg-background-highlight py-6" >
78
+ < div className = "flex flex-col gap-6" >
79
+ { /* First Carousel */ }
80
+ < Carousel
81
+ setApi = { setApi1 }
82
+ className = "w-full px-16"
83
+ opts = { {
84
+ align : "center" ,
85
+ containScroll : false ,
86
+ loop : false ,
87
+ startIndex : findLatestReleaseIndex ( ) ,
88
+ } }
89
+ >
90
+ < CarouselContent >
91
+ { releasesData . map ( ( release ) => (
92
+ < CarouselItem
93
+ key = { release . releaseName }
94
+ className = "w-full lg:basis-1/3"
95
+ >
96
+ < div className = "flex w-full flex-col items-center justify-center bg-blue-400" >
97
+ < p > { release . releaseName } </ p >
98
+ </ div >
99
+ </ CarouselItem >
100
+ ) ) }
101
+ </ CarouselContent >
102
+ < div className = "lg:hidden" >
103
+ < CarouselPrevious />
104
+ < CarouselNext />
105
+ </ div >
106
+ </ Carousel >
107
+
108
+ { /* Second Carousel */ }
109
+ < Carousel
110
+ setApi = { setApi2 }
111
+ className = "w-full px-4 lg:px-16"
112
+ opts = { {
113
+ align : "center" ,
114
+ containScroll : false ,
115
+ loop : false ,
116
+ startIndex : findLatestReleaseIndex ( ) ,
117
+ } }
118
+ >
119
+ < CarouselContent >
120
+ { releasesData . map ( ( release ) => (
121
+ < CarouselItem
122
+ key = { release . releaseName }
123
+ className = "w-full pl-4"
124
+ >
125
+ < div className = "flex w-full flex-col items-center justify-center bg-red-500" >
126
+ < p > { release . releaseDate } </ p >
127
+ </ div >
128
+ </ CarouselItem >
129
+ ) ) }
130
+ </ CarouselContent >
131
+ < div className = "hidden lg:block" >
132
+ < CarouselPrevious />
133
+ < CarouselNext />
134
+ </ div >
135
+ </ Carousel >
136
+ </ div >
137
+ </ div >
138
+ </ div >
139
+ </ div >
140
+ )
141
+ }
142
+
143
+ export default ReleaseCarousel
144
+
145
+ {
146
+ /* <div className="gap-6 rounded-2xl bg-background-highlight p-6">
147
+ <div className="items-center justify-between gap-2">
100
148
<div className="flex lg:hidden">
101
149
<PreviousButton />
102
150
</div>
103
- < SwiperContainer className = "w-full overflow-hidden" ref = { containerRef2 } >
151
+ <div className="flex flex-1">
152
+ <SwiperContainer className="" ref={containerRef2}>
104
153
<Swiper
105
- slidesPerView = { 3 }
106
154
spaceBetween={0}
107
155
ref={swiperRef2}
108
156
initialSlide={activeSlide}
109
157
centeredSlides={true}
158
+ breakpoints={{
159
+ 320: {
160
+ slidesPerView: 1,
161
+ },
162
+ 768: {
163
+ slidesPerView: 3,
164
+ },
165
+ }}
110
166
>
111
167
{releasesData.map((release, index) => {
112
168
const releaseDate = new Date(release.releaseDate)
@@ -119,7 +175,7 @@ const ReleaseCarousel = () => {
119
175
return (
120
176
<SwiperSlide
121
177
key={release.releaseName}
122
- className = "!w-1/3 items-center justify-center text-center"
178
+ className="items-center justify-center text-center md:!w-1/3 "
123
179
>
124
180
<div className="mb-3 h-6">
125
181
{pastReleases[pastReleases.length - 1].releaseDate ===
@@ -169,15 +225,18 @@ const ReleaseCarousel = () => {
169
225
)}
170
226
/>
171
227
</div>
172
- < p className = "text-md font-bold" > { release . releaseName } </ p >
173
- < p className = "font-mono text-sm text-body-medium" >
174
- { formatReleaseDate ( release . releaseDate ) }
175
- </ p >
228
+ <div className="flex flex-col items-center justify-center text-center">
229
+ <p className="text-md font-bold">{release.releaseName}</p>
230
+ <p className="font-mono text-sm text-body-medium">
231
+ {formatReleaseDate(release.releaseDate)}
232
+ </p>
233
+ </div>
176
234
</SwiperSlide>
177
235
)
178
236
}) }
179
237
</Swiper>
180
238
</SwiperContainer>
239
+ </div>
181
240
<div className="flex lg:hidden">
182
241
<NextButton />
183
242
</div>
@@ -234,8 +293,5 @@ const ReleaseCarousel = () => {
234
293
<NextButton />
235
294
</div>
236
295
</div>
237
- </ div >
238
- )
296
+ </div> */
239
297
}
240
-
241
- export default ReleaseCarousel
0 commit comments