|
| 1 | +import Title from "./title"; |
| 2 | +import Container from "react-bootstrap/Container"; |
| 3 | +import Row from "react-bootstrap/Row"; |
| 4 | +import Col from "react-bootstrap/Col"; |
| 5 | +import eventimg from "../../assets/LandingPage/pr-1.jpg"; |
| 6 | +import Button from "./button"; |
| 7 | +import { ChevronLeft, ChevronRight } from "react-bootstrap-icons"; |
| 8 | +import React, { useState, useEffect } from "react"; |
| 9 | + |
| 10 | +function PastEvent() { |
| 11 | + const PastEventArray = [ |
| 12 | + { title: "event title 1", image: eventimg }, |
| 13 | + { title: "event title 2", image: eventimg }, |
| 14 | + { title: "event title 3", image: eventimg }, |
| 15 | + { title: "event title 4", image: eventimg }, |
| 16 | + { title: "event title 5", image: eventimg }, |
| 17 | + { title: "event title 6", image: eventimg }, |
| 18 | + { title: "event title 7", image: eventimg }, |
| 19 | + { title: "event title 8", image: eventimg }, |
| 20 | + ]; |
| 21 | + |
| 22 | + const [currentIndex, setCurrentIndex] = useState(0); |
| 23 | + const itemsToShow = 4; |
| 24 | + |
| 25 | + const getVisibleItems = () => { |
| 26 | + return Array.from({ length: itemsToShow }, (_, i) => { |
| 27 | + const index = (currentIndex + i) % PastEventArray.length; |
| 28 | + return PastEventArray[index]; |
| 29 | + }); |
| 30 | + }; |
| 31 | + |
| 32 | + const handleNavigation = (direction) => { |
| 33 | + setCurrentIndex((prevIndex) => { |
| 34 | + const newIndex = (prevIndex + direction + PastEventArray.length) % PastEventArray.length; |
| 35 | + return newIndex; |
| 36 | + }); |
| 37 | + }; |
| 38 | + |
| 39 | + |
| 40 | + const visibleItems = getVisibleItems(); |
| 41 | + |
| 42 | + const prevItem = () => handleNavigation(-itemsToShow); |
| 43 | + const nextItem = () => handleNavigation(itemsToShow); |
| 44 | + |
| 45 | + return ( |
| 46 | + <div style={{ display: 'flex', alignItems: 'center' }}> |
| 47 | + <button onClick={prevItem} className="herobutton" disabled={currentIndex === 0}> |
| 48 | + <ChevronLeft /> |
| 49 | + </button> |
| 50 | + <Container> |
| 51 | + <Title title={"GALLERY"} head={"Sneak Peek From Past Events"} /> |
| 52 | + <Row> |
| 53 | + {visibleItems.map((item, index) => ( |
| 54 | + <Col md={3} key={index} className="Announcement-individual"> |
| 55 | + <img src={item.image} className="Announcement-individual__image" alt={`image of ${item.title}`} /> |
| 56 | + <div style={{ padding: '1rem 0rem' }}> |
| 57 | + <h2 className="Announcement-individual__title">{item.title}</h2> |
| 58 | + </div> |
| 59 | + <Button buttontext={"View More"} buttonclass={"eventbutton"} /> |
| 60 | + </Col> |
| 61 | + ))} |
| 62 | + </Row> |
| 63 | + </Container> |
| 64 | + <button onClick={nextItem} className="herobutton" disabled={currentIndex + itemsToShow >= PastEventArray.length}> |
| 65 | + <ChevronRight /> |
| 66 | + </button> |
| 67 | + </div> |
| 68 | + ); |
| 69 | +} |
| 70 | + |
| 71 | +export default PastEvent; |
0 commit comments