|
1 | 1 | import { useState } from 'react'; |
2 | 2 | import '../css/carousel.css'; |
3 | | -import Organization from './Organization'; |
4 | 3 |
|
5 | | -type CarouselProps = { |
6 | | - type: string; |
7 | | -}; |
| 4 | +import EventPanel from './EventCarouselPanel.tsx'; |
| 5 | +import OrganizationPanel from './OrganizationCarouselPanel.tsx'; |
8 | 6 |
|
9 | | -export default function Carousel({ type }: CarouselProps) { |
10 | | - const [active, setActive] = useState(0); |
| 7 | +import type { Event } from '../types/Event.ts'; |
| 8 | +import type { Organization } from '../types/Organization.ts'; |
| 9 | + |
| 10 | +type CarouselProps = |
| 11 | + | { type: 'event'; title: string; data: Event[] } |
| 12 | + | { type: 'organization'; title: string; data: Organization[] }; |
11 | 13 |
|
12 | | - const organizations = [ |
13 | | - { title: 'Math Club', desc: 'The RPI Math Faculty approved and Union affiliated math club!' }, |
14 | | - { title: 'Science Club', desc: 'The RPI Math Faculty approved and Union affiliated science club!' }, |
15 | | - { title: 'Gym Club', desc: 'The RPI Math Faculty approved and Union affiliated gym club!' }, |
16 | | - { title: 'Dance Club', desc: 'The RPI Math Faculty approved and Union affiliated dance club!' }, |
17 | | - { title: 'English Club', desc: 'The RPI Math Faculty approved and Union affiliated english club!' }, |
18 | | - { title: 'Coding Club', desc: 'The RPI Math Faculty approved and Union affiliated coding club!' }, |
19 | | - { title: 'Archery Club', desc: 'The RPI Math Faculty approved and Union affiliated archery club!' }, |
20 | | - { title: 'Golf Club', desc: 'The RPI Math Faculty approved and Union affiliated golf club!' }, |
21 | | - { title: 'Running Club', desc: 'The RPI Math Faculty approved and Union affiliated running club!' }, |
22 | | - { title: 'Study Club', desc: 'The RPI Math Faculty approved and Union affiliated study club!' }, |
23 | | - ]; |
| 14 | +export default function Carousel({ type, title, data }: CarouselProps) { |
| 15 | + console.log(data); |
| 16 | + const [active, setActive] = useState(0); |
24 | 17 |
|
25 | 18 | const moveLeft = () => { |
26 | 19 | setActive((prev) => Math.max(prev - 1, 0)); |
27 | 20 | }; |
28 | 21 |
|
29 | 22 | const moveRight = () => { |
30 | | - setActive((prev) => Math.min(prev + 1, organizations.length - 1)); |
| 23 | + setActive((prev) => Math.min(prev + 1, data.length - 1)); |
31 | 24 | }; |
32 | 25 |
|
33 | 26 | return ( |
34 | 27 | <div className="carousel-container"> |
35 | | - <span className="carousel-title">{type}</span> |
| 28 | + <span className="carousel-title">{title}</span> |
36 | 29 |
|
37 | 30 | <div className="carousel-wrapper"> |
38 | 31 | <button className="carousel-arrow left" onClick={moveLeft}> |
39 | 32 | ‹ |
40 | 33 | </button> |
41 | 34 |
|
42 | 35 | <div className="carousel"> |
43 | | - {organizations.map((org, index) => { |
44 | | - const offset = index - active; |
45 | | - return ( |
46 | | - <Organization |
47 | | - key={index} |
48 | | - className={`carousel-item offset-${offset}`} |
49 | | - title={org.title} |
50 | | - desc={org.desc} |
51 | | - onClick={() => setActive(index)} |
52 | | - /> |
53 | | - ); |
54 | | - })} |
| 36 | + {type === 'event' |
| 37 | + ? data.map((event, index) => { |
| 38 | + const offset = index - active; |
| 39 | + |
| 40 | + return ( |
| 41 | + <EventPanel |
| 42 | + event={event} |
| 43 | + className={`carousel-item offset-${offset}`} |
| 44 | + onClick={() => setActive(index)} |
| 45 | + /> |
| 46 | + ); |
| 47 | + }) |
| 48 | + : data.map((org, index) => { |
| 49 | + const offset = index - active; |
| 50 | + |
| 51 | + return ( |
| 52 | + <OrganizationPanel |
| 53 | + organization={org} |
| 54 | + className={`carousel-item offset-${offset}`} |
| 55 | + onClick={() => setActive(index)} |
| 56 | + /> |
| 57 | + ); |
| 58 | + })} |
55 | 59 | </div> |
56 | 60 |
|
57 | 61 | <button className="carousel-arrow right" onClick={moveRight}> |
|
0 commit comments