summaryrefslogtreecommitdiff
path: root/client/src/components/Home.tsx
blob: 79743a5b4c55a1ef461be6f91a0c2d62ed743ada (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import React from 'react';
import { useEffect, useState } from 'react';
import './Carousel.css';
import { BlurryLoadImg } from './BlurryLoadImg';

const images = [
  { small: '/small/engagement1.webp', full: '/full/engagement1.jpg' },
  { small: '/small/engagement2.webp', full: '/full/engagement2.jpg' },
  { small: '/small/engagement3.webp', full: '/full/engagement3.jpg' },
  { small: '/small/engagement4.webp', full: '/full/engagement4.jpg' },
  { small: '/small/engagement5.webp', full: '/full/engagement5.jpg' },
  { small: '/small/engagement6.webp', full: '/full/engagement6.jpg' },
];

function Home() {
  const [currentIndex, setIndex] = useState<number>(0);

  useEffect(() => {
    const interval = setInterval(() => {
      setIndex((prevIndex) =>
        prevIndex === images.length - 1 ? 0 : prevIndex + 1
      );
    }, 3000);
    return () => clearInterval(interval);
  }, [images.length]);

  return (
    <div className="carousel-container">
      <div className="carousel">
        {images.map((image, index) => (
          <div
            key={index}
            className={
              index === currentIndex
                ? 'carousel-slide active-slide'
                : 'carousel-slide'
            }
          >
            <BlurryLoadImg
              src={image.small}
              data-large={`${image.full}`}
            ></BlurryLoadImg>
          </div>
        ))}
      </div>
    </div>
  );
}

export default Home;