11import React , { useState , useRef , TouchEvent } from 'react' ;
2- import ToolCard from './TryCard' ;
3- import CardData from '../constants/TryCardData' ;
2+ import { TryCard , ActivityCard } from './TryCard' ;
3+ import { TryCardData , Activities } from '../constants/TryCardData' ;
44
55const Try : React . FC = ( ) => {
66 const [ currentCard , setCurrentCard ] = useState ( 0 ) ;
77 const [ touchStart , setTouchStart ] = useState < number > ( 0 ) ;
88 const [ touchEnd , setTouchEnd ] = useState < number > ( 0 ) ;
99 const [ isDragging , setIsDragging ] = useState ( false ) ;
10+ const [ currentActivity , setCurrentActivity ] = useState ( 0 ) ;
1011 const carouselRef = useRef < HTMLDivElement > ( null ) ;
1112
12- const handleSwipe = ( direction : 'next' | 'prev' ) => {
13+ const handleSwipe = (
14+ direction : 'next' | 'prev' ,
15+ setCurrent : React . Dispatch < React . SetStateAction < number > > ,
16+ length : number ,
17+ ) => {
1318 if ( direction === 'next' ) {
14- setCurrentCard ( ( prev ) => ( prev + 1 ) % CardData . length ) ;
19+ setCurrent ( ( prev ) => ( prev + 1 ) % length ) ;
1520 } else {
16- setCurrentCard ( ( prev ) => ( prev - 1 + CardData . length ) % CardData . length ) ;
21+ setCurrent ( ( prev ) => ( prev - 1 + length ) % length ) ;
1722 }
1823 } ;
1924
@@ -26,16 +31,19 @@ const Try: React.FC = () => {
2631 setTouchEnd ( e . targetTouches [ 0 ] . clientX ) ;
2732 } ;
2833
29- const handleTouchEnd = ( ) => {
34+ const handleTouchEnd = (
35+ setCurrent : React . Dispatch < React . SetStateAction < number > > ,
36+ length : number ,
37+ ) => {
3038 setIsDragging ( false ) ;
3139 const swipeThreshold = 50 ;
3240 const swipeDistance = touchStart - touchEnd ;
3341
3442 if ( Math . abs ( swipeDistance ) > swipeThreshold ) {
3543 if ( swipeDistance > 0 ) {
36- handleSwipe ( 'next' ) ;
44+ handleSwipe ( 'next' , setCurrent , length ) ;
3745 } else {
38- handleSwipe ( 'prev' ) ;
46+ handleSwipe ( 'prev' , setCurrent , length ) ;
3947 }
4048 }
4149 } ;
@@ -67,8 +75,8 @@ const Try: React.FC = () => {
6775
6876 { /* Desktop Grid */ }
6977 < div className = "hidden md:grid md:grid-cols-3 gap-8" >
70- { CardData . map ( ( card , index ) => (
71- < ToolCard key = { index } { ...card } />
78+ { TryCardData . map ( ( card , index ) => (
79+ < TryCard key = { index } { ...card } />
7280 ) ) }
7381 </ div >
7482
@@ -80,7 +88,9 @@ const Try: React.FC = () => {
8088 className = "overflow-hidden touch-pan-x"
8189 onTouchStart = { handleTouchStart }
8290 onTouchMove = { handleTouchMove }
83- onTouchEnd = { handleTouchEnd }
91+ onTouchEnd = { ( ) =>
92+ handleTouchEnd ( setCurrentCard , TryCardData . length )
93+ }
8494 >
8595 < div
8696 className = { `flex transition-transform duration-300 ease-out` }
@@ -89,7 +99,7 @@ const Try: React.FC = () => {
8999 willChange : 'transform' ,
90100 } }
91101 >
92- { CardData . map ( ( card , index ) => (
102+ { TryCardData . map ( ( card , index ) => (
93103 < div
94104 key = { index }
95105 className = "w-full flex-shrink-0 px-2"
@@ -101,7 +111,7 @@ const Try: React.FC = () => {
101111 ${ isDragging ? 'scale-98' : 'hover:scale-102' }
102112 ` }
103113 >
104- < ToolCard { ...card } />
114+ < TryCard { ...card } />
105115 </ div >
106116 </ div >
107117 ) ) }
@@ -111,7 +121,9 @@ const Try: React.FC = () => {
111121 { /* Navigation Buttons */ }
112122 < div className = "absolute top-1/2 -translate-y-1/2 left-0 right-0 flex justify-between pointer-events-none" >
113123 < button
114- onClick = { ( ) => handleSwipe ( 'prev' ) }
124+ onClick = { ( ) =>
125+ handleSwipe ( 'prev' , setCurrentCard , TryCardData . length )
126+ }
115127 className = "pointer-events-auto p-3 bg-white/80 text-[#975555] rounded-full shadow-lg hover:bg-white transition-all"
116128 aria-label = "Previous"
117129 >
@@ -130,7 +142,9 @@ const Try: React.FC = () => {
130142 </ svg >
131143 </ button >
132144 < button
133- onClick = { ( ) => handleSwipe ( 'next' ) }
145+ onClick = { ( ) =>
146+ handleSwipe ( 'next' , setCurrentCard , TryCardData . length )
147+ }
134148 className = "pointer-events-auto p-3 bg-white/80 text-[#975555] rounded-full shadow-lg hover:bg-white transition-all"
135149 aria-label = "Next"
136150 >
@@ -153,7 +167,7 @@ const Try: React.FC = () => {
153167
154168 { /* Dots Indicator */ }
155169 < div className = "flex justify-center space-x-2 mt-6" >
156- { CardData . map ( ( _ , index ) => (
170+ { TryCardData . map ( ( _ , index ) => (
157171 < button
158172 key = { index }
159173 onClick = { ( ) => setCurrentCard ( index ) }
@@ -168,6 +182,138 @@ const Try: React.FC = () => {
168182 </ div >
169183 </ div >
170184 </ div >
185+
186+ < div className = "max-w-6xl mx-auto space-y-8 mt-16" >
187+ < header className = "space-y-6" >
188+ < h1 className = "text-5xl md:text-7xl font-bold flex flex-col sm:flex-row items-start sm:items-center" >
189+ < span className = "text-white bg-[#975555] px-2 py-1 rounded-lg inline-block" >
190+ ALREADY USING
191+ </ span >
192+ < span className = "text-black sm:ml-2 mt-2 sm:mt-0" > SUGAR?</ span >
193+ </ h1 >
194+ < div className = "space-y-4" >
195+ < p className = "text-[#975555] text-2xl md:text-4xl font-bold leading-tight" >
196+ "We have many activities for you!"
197+ </ p >
198+ < i className = "text-xs text-gray-700" >
199+ The Sugar Learning platform is a complete environment for
200+ teaching and learning, which includes individual activities. If
201+ you're already using the Sugar Desktop Environment, then you can
202+ install from the activities below, which has links to some of
203+ our most popular activities.
204+ </ i >
205+ </ div >
206+ </ header >
207+
208+ { /* Desktop Grid */ }
209+ < div className = "hidden md:grid md:grid-cols-3 gap-8" >
210+ { Activities . map ( ( activity , index ) => (
211+ < ActivityCard key = { index } { ...activity } />
212+ ) ) }
213+ </ div >
214+
215+ { /* Mobile Carousel */ }
216+ < div className = "md:hidden ml-[-1rem] mr-[-1rem]" >
217+ < div className = "relative px-4" >
218+ < div
219+ ref = { carouselRef }
220+ className = "overflow-hidden touch-pan-x"
221+ onTouchStart = { handleTouchStart }
222+ onTouchMove = { handleTouchMove }
223+ onTouchEnd = { ( ) =>
224+ handleTouchEnd ( setCurrentActivity , Activities . length )
225+ }
226+ >
227+ < div
228+ className = { `flex transition-transform duration-300 ease-out` }
229+ style = { {
230+ transform : `translateX(-${ currentActivity * 100 } %)` ,
231+ willChange : 'transform' ,
232+ } }
233+ >
234+ { Activities . map ( ( activity , index ) => (
235+ < div
236+ key = { index }
237+ className = "w-full flex-shrink-0 px-2"
238+ style = { { scrollSnapAlign : 'start' } }
239+ >
240+ < div
241+ className = { `
242+ transform transition-all duration-300
243+ ${ isDragging ? 'scale-98' : 'hover:scale-102' }
244+ ` }
245+ >
246+ < ActivityCard { ...activity } />
247+ </ div >
248+ </ div >
249+ ) ) }
250+ </ div >
251+ </ div >
252+
253+ { /* Navigation Buttons */ }
254+ < div className = "absolute top-1/2 -translate-y-1/2 left-0 right-0 flex justify-between pointer-events-none" >
255+ < button
256+ onClick = { ( ) =>
257+ handleSwipe ( 'prev' , setCurrentActivity , Activities . length )
258+ }
259+ className = "pointer-events-auto p-3 bg-white/80 text-[#975555] rounded-full shadow-lg hover:bg-white transition-all"
260+ aria-label = "Previous"
261+ >
262+ < svg
263+ className = "w-6 h-6"
264+ fill = "none"
265+ stroke = "currentColor"
266+ viewBox = "0 0 24 24"
267+ >
268+ < path
269+ strokeLinecap = "round"
270+ strokeLinejoin = "round"
271+ strokeWidth = { 2 }
272+ d = "M15 19l-7-7 7-7"
273+ />
274+ </ svg >
275+ </ button >
276+ < button
277+ onClick = { ( ) =>
278+ handleSwipe ( 'next' , setCurrentActivity , Activities . length )
279+ }
280+ className = "pointer-events-auto p-3 bg-white/80 text-[#975555] rounded-full shadow-lg hover:bg-white transition-all"
281+ aria-label = "Next"
282+ >
283+ < svg
284+ className = "w-6 h-6"
285+ fill = "none"
286+ stroke = "currentColor"
287+ viewBox = "0 0 24 24"
288+ >
289+ < path
290+ strokeLinecap = "round"
291+ strokeLinejoin = "round"
292+ strokeWidth = { 2 }
293+ d = "M9 5l7 7-7 7"
294+ />
295+ </ svg >
296+ </ button >
297+ </ div >
298+ </ div >
299+
300+ { /* Dots Indicator */ }
301+ < div className = "flex justify-center space-x-2 mt-6" >
302+ { Activities . map ( ( _ , index ) => (
303+ < button
304+ key = { index }
305+ onClick = { ( ) => setCurrentActivity ( index ) }
306+ className = { `w-2.5 h-2.5 rounded-full transition-all duration-300 ${
307+ currentActivity === index
308+ ? 'bg-[#975555] w-6'
309+ : 'bg-[#975555]/30'
310+ } `}
311+ aria-label = { `Go to slide ${ index + 1 } ` }
312+ />
313+ ) ) }
314+ </ div >
315+ </ div >
316+ </ div >
171317 </ main >
172318 </ div >
173319 ) ;
0 commit comments