Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events page fix #25

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions src/pages/events.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import 'swiper/css/navigation';
import { Autoplay, EffectCoverflow, Pagination } from 'swiper/modules';
import { useNavigate } from 'react-router-dom';

// Utility function to load images dynamically
const importAll = (r) => {
let images = {};
r.keys().map((item, index) => { images[item.replace('./', '')] = r(item); });
r.keys().map((item) => {
images[item.replace('./', '')] = r(item);
return null;
});
return images;
}
};

// Load all images from the events subfolders
const images = importAll(require.context('../data/images/events', true, /main\.jpg$/));

const Events = () => {
Expand All @@ -24,10 +25,10 @@ const Events = () => {
const [currentEvent, setCurrentEvent] = useState('');

useEffect(() => {
const eventSlides = Object.keys(images).map((key, index) => {
const eventName = `Event${index + 1}`;
return { src: images[key], eventName };
});
const eventSlides = Object.keys(images).map((key, index) => ({
src: images[key],
eventName: `Event${index + 1}`,
}));
setSlides(eventSlides);
if (eventSlides.length > 0) {
setCurrentEvent(eventSlides[0].eventName);
Expand All @@ -39,14 +40,14 @@ const Events = () => {
};

const handleSlideChange = (swiper) => {
setCurrentEvent(slides[swiper.activeIndex].eventName);
setCurrentEvent(slides[swiper.activeIndex]?.eventName || '');
};

return (
<div className="min-h-screen gradient events-container">
<div className="text-white text-6xl font-bold text-center pt-12 pb-4">{currentEvent}</div>
<Swiper
effect={"coverflow"}
effect="coverflow"
grabCursor={true}
centeredSlides={true}
loop={false}
Expand All @@ -57,25 +58,23 @@ const Events = () => {
depth: 100,
modifier: 1,
}}
pagination={{ el: '.swiper-pagination', clickable: true }}
pagination={{ clickable: true }}
modules={[Autoplay, EffectCoverflow, Pagination]}
className="swiper-container"
onSlideChange={handleSlideChange}
autoplay={{
delay: 2000,
stopOnLastSlide: false,
disableOnInteraction: false,
speed: 500
speed: 500,
}}
>
{slides.map((slide, index) => (
<SwiperSlide key={index}>
<img src={slide.src} alt={slide.eventName} />
</SwiperSlide>
))}
<div className="slider-controler">
<div className="swiper-pagination"></div>
</div>
<div className="swiper-pagination"></div>
</Swiper>
<button
className='border-2 border-solid border-teal-500 p-3 rounded-full bg-gradient-to-r from-b_col1 to-b_col2 float-end'
Expand Down
12 changes: 5 additions & 7 deletions src/pages/gallery.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import 'swiper/css/navigation';
import { Autoplay, EffectCoverflow, Pagination } from 'swiper/modules';

const Gallery = ({ slides }) => {
const [currentEvent, setCurrentEvent] = useState(slides[0].eventName);
const [currentEvent, setCurrentEvent] = useState(slides[0]?.eventName || '');

const handleSlideChange = (swiper) => {
setCurrentEvent(slides[swiper.activeIndex].eventName);
setCurrentEvent(slides[swiper.activeIndex]?.eventName || '');
};

return (
<div className="min-h-screen bg-slate-950 events-container">
<div className="text-white text-9xl font-bold text-center pb-16">{currentEvent}</div>
<Swiper
effect={"coverflow"}
effect="coverflow"
grabCursor={true}
centeredSlides={true}
loop={true}
Expand All @@ -28,7 +28,7 @@ const Gallery = ({ slides }) => {
depth: 350,
modifier: 1,
}}
pagination={{ el: '.swiper-pagination', clickable: true }}
pagination={{ clickable: true }}
modules={[Autoplay, EffectCoverflow, Pagination]}
onSlideChange={handleSlideChange}
autoplay={{
Expand All @@ -50,9 +50,7 @@ const Gallery = ({ slides }) => {
</section>
</SwiperSlide>
))}
<div className="slider-controler">
<div className="swiper-pagination"></div>
</div>
<div className="swiper-pagination"></div>
</Swiper>
</div>
);
Expand Down
Loading