photo gallery and phot gallery details page updated for api datas
This commit is contained in:
parent
782616940d
commit
317c611339
@ -5,112 +5,121 @@ import Link from "next/link";
|
||||
import { useState, useEffect } from 'react';
|
||||
|
||||
export default function Memories() {
|
||||
|
||||
const [selectedYear, setSelectedYear] = useState('');
|
||||
const [events, setEvents]=useState([]);
|
||||
const [years, setYears] = useState([]);
|
||||
const [selectedYear, setSelectedYear] = useState('');
|
||||
const [events, setEvents] = useState([]);
|
||||
const [years, setYears] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
getEvents();
|
||||
}, [])
|
||||
useEffect(() => {
|
||||
getEvents();
|
||||
}, []);
|
||||
|
||||
const getEvents = async () => {
|
||||
try {
|
||||
const eventRes = await axios?.get('https://api.tamilculturewaterloo.org/api/events/');
|
||||
console.log("eventRes", eventRes)
|
||||
setEvents(eventRes?.data?.data)
|
||||
const years = Object.keys(eventRes?.data).sort((a, b) => Number(b) - Number(a));
|
||||
setYears(years);
|
||||
const getEvents = async () => {
|
||||
try {
|
||||
const eventRes = await axios.get(
|
||||
'https://api.tamilculturewaterloo.org/api/events/'
|
||||
);
|
||||
|
||||
// Default to latest year
|
||||
if (years.length > 0) {
|
||||
setSelectedYear(years[0]);
|
||||
}
|
||||
const eventsData = eventRes?.data?.data || [];
|
||||
setEvents(eventsData);
|
||||
|
||||
} catch (error) {
|
||||
console.log("error fetching data", error)
|
||||
}
|
||||
// Extract unique years & sort (latest first)
|
||||
const uniqueYears = [...new Set(eventsData.map(event => event.year))].sort((a, b) => b - a);
|
||||
setYears(uniqueYears);
|
||||
|
||||
// Default to latest year immediately
|
||||
if (uniqueYears.length > 0) {
|
||||
setSelectedYear(uniqueYears[0]);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("error fetching data", error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Layout headerStyle={1} footerStyle={1}>
|
||||
<div>
|
||||
{/* Header Section */}
|
||||
<div
|
||||
className="inner-page-header"
|
||||
style={{ backgroundImage: 'url(/assets/img/event/gallery/gallery-banner.webp)' }}
|
||||
>
|
||||
<div className="container">
|
||||
<div className="row">
|
||||
<div className="col-lg-6 m-auto">
|
||||
<div className="heading1 text-center">
|
||||
<h1>Recent Memories</h1>
|
||||
<div className="space20" />
|
||||
<Link href="/">
|
||||
Home <i className="fa-solid fa-angle-right" /> <span>Recent Memories</span>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Memory Section */}
|
||||
<div className="memory-inner-section-area blog-details-section sp4">
|
||||
<div className="container">
|
||||
<div className="row gx-5">
|
||||
{/* Left Column: Year Tabs */}
|
||||
<div className="col-lg-3 mb-4 mb-lg-0">
|
||||
<div className="blog-auhtor-details sticky-top" style={{ top: "120px" }}>
|
||||
<div className="blog-categories">
|
||||
<ul className="list-unstyled">
|
||||
{years.map((year) => (
|
||||
<li key={year}>
|
||||
<button
|
||||
onClick={() => setSelectedYear(year)}
|
||||
className={`btn w-100 mb-2 category-btn ${selectedYear === year && 'active'}`}
|
||||
>
|
||||
Years {year}
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right Column: Gallery */}
|
||||
<div className="col-lg-9">
|
||||
{/* <div className="heading12 mb-4 border-bottom pb-2">
|
||||
<h2 className="text-center">📷 Memories of {selectedYear}</h2>
|
||||
</div> */}
|
||||
|
||||
<div className="row justify-content-start">
|
||||
{events[selectedYear]?.map((event, idx) => (
|
||||
<div className="col-lg-4 col-md-6 mb-4" key={idx}>
|
||||
<div className="memory3-boxarea">
|
||||
<div className="img1">
|
||||
<img src={event.image} alt={event.title} />
|
||||
</div>
|
||||
<div className="content-area">
|
||||
<p>{event.date}</p>
|
||||
<div className="space12" />
|
||||
<Link href={`/photo-gallery/single-gallery?slug=${event.slug}`}>{event.title}</Link>
|
||||
<div className="plus">
|
||||
<Link href={`/photo-gallery/single-gallery?slug=${event.slug}`}>
|
||||
<i className="fa-solid fa-plus" />
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
// Filter events by selected year
|
||||
const filteredEvents = events.filter(event => event.year === selectedYear);
|
||||
|
||||
return (
|
||||
<Layout headerStyle={1} footerStyle={1}>
|
||||
<div>
|
||||
{/* Header Section */}
|
||||
<div
|
||||
className="inner-page-header"
|
||||
style={{ backgroundImage: 'url(/assets/img/event/gallery/gallery-banner.webp)' }}
|
||||
>
|
||||
<div className="container">
|
||||
<div className="row">
|
||||
<div className="col-lg-6 m-auto">
|
||||
<div className="heading1 text-center">
|
||||
<h1>Recent Memories</h1>
|
||||
<div className="space20" />
|
||||
<Link href="/">
|
||||
Home <i className="fa-solid fa-angle-right" /> <span>Recent Memories</span>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Layout>
|
||||
);
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Memory Section */}
|
||||
<div className="memory-inner-section-area blog-details-section sp4">
|
||||
<div className="container">
|
||||
<div className="row gx-5">
|
||||
{/* Left Column: Year Tabs */}
|
||||
<div className="col-lg-3 mb-4 mb-lg-0">
|
||||
<div className="blog-auhtor-details sticky-top" style={{ top: "120px" }}>
|
||||
<div className="blog-categories">
|
||||
<ul className="list-unstyled">
|
||||
{years.map((year) => (
|
||||
<li key={year}>
|
||||
<button
|
||||
onClick={() => setSelectedYear(year)}
|
||||
className={`btn w-100 mb-2 category-btn ${selectedYear === year ? 'active' : ''}`}
|
||||
>
|
||||
Year {year}
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right Column: Gallery */}
|
||||
<div className="col-lg-9">
|
||||
<div className="row justify-content-start">
|
||||
{filteredEvents.map((event, idx) => (
|
||||
<div className="col-lg-4 col-md-6 mb-4" key={idx}>
|
||||
<div className="memory3-boxarea">
|
||||
<div className="img1">
|
||||
<img src={event.eventimageurl} alt={event.eventtitle} />
|
||||
</div>
|
||||
<div className="content-area">
|
||||
<p>{event.eventdate}</p>
|
||||
<div className="space12" />
|
||||
<Link href={`/photo-gallery/single-gallery?id=${event.id}`}>
|
||||
{event.eventtitle}
|
||||
</Link>
|
||||
<div className="plus">
|
||||
<Link href={`/photo-gallery/single-gallery?id=${event.id}`}>
|
||||
<i className="fa-solid fa-plus" />
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{filteredEvents.length === 0 && (
|
||||
<div className="col-12 text-center">
|
||||
<p>No events found for {selectedYear}</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,122 +1,136 @@
|
||||
'use client';
|
||||
|
||||
import Layout from '@/components/layout/Layout';
|
||||
import { memoryData } from '@/utility/constant.utils';
|
||||
import axios from 'axios';
|
||||
import Link from 'next/link';
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
import { useState } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import Lightbox from "yet-another-react-lightbox";
|
||||
import "yet-another-react-lightbox/styles.css";
|
||||
|
||||
interface EventData {
|
||||
image: string;
|
||||
title: string;
|
||||
desc?: string;
|
||||
date: string;
|
||||
slug: string;
|
||||
link?: string;
|
||||
gallery?: string[];
|
||||
interface EventImage {
|
||||
id: string;
|
||||
src: string;
|
||||
title?: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export default function SingleGallery() {
|
||||
const searchParams = useSearchParams();
|
||||
const slug = searchParams.get('slug');
|
||||
const searchParams = useSearchParams();
|
||||
const eventId = searchParams.get('id');
|
||||
|
||||
// Flatten all events into a single array
|
||||
const allEvents: EventData[] = Object.values(memoryData).flat();
|
||||
const [eventImages, setEventImages] = useState<EventImage[]>([]);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [currentIndex, setCurrentIndex] = useState(0);
|
||||
|
||||
// Match event by slug
|
||||
const matchedEvent = allEvents.find(event => event.slug === slug);
|
||||
const galleryImages: string[] = matchedEvent?.gallery || [];
|
||||
useEffect(() => {
|
||||
if (eventId) {
|
||||
getEventGallery();
|
||||
}
|
||||
}, [eventId]);
|
||||
|
||||
const [open, setOpen] = useState<boolean>(false);
|
||||
const [currentIndex, setCurrentIndex] = useState<number>(0);
|
||||
const getEventGallery = async () => {
|
||||
try {
|
||||
const res = await axios.get(
|
||||
`https://api.tamilculturewaterloo.org/api/event-images/event/${eventId}`
|
||||
);
|
||||
const formatted = res.data?.data?.map((img: any) => ({
|
||||
id: img.id,
|
||||
src: img.imageurl,
|
||||
title: img?.title || '',
|
||||
description: img?.description || '',
|
||||
}));
|
||||
setEventImages(formatted || []);
|
||||
} catch (error) {
|
||||
console.log("Error fetching event images", error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleImageClick = (index: number) => {
|
||||
setCurrentIndex(index);
|
||||
setOpen(true);
|
||||
};
|
||||
const handleImageClick = (index: number) => {
|
||||
setCurrentIndex(index);
|
||||
setOpen(true);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Layout headerStyle={1} footerStyle={1}>
|
||||
{/* Header Section */}
|
||||
<div
|
||||
className="inner-page-header"
|
||||
style={{ backgroundImage: 'url(/assets/img/bg/header-bg11.png)' }}
|
||||
>
|
||||
<div className="container">
|
||||
<div className="row">
|
||||
<div className="col-lg-6 m-auto">
|
||||
<div className="heading1 text-center">
|
||||
<h1>Recent Memories</h1>
|
||||
<div className="space20" />
|
||||
<Link href="/">
|
||||
Home <i className="fa-solid fa-angle-right" /> <span>Recent Memories</span>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
return (
|
||||
<Layout headerStyle={1} footerStyle={1}>
|
||||
{/* Header Section */}
|
||||
<div
|
||||
className="inner-page-header"
|
||||
style={{ backgroundImage: 'url(/assets/img/bg/header-bg11.png)' }}
|
||||
>
|
||||
<div className="container">
|
||||
<div className="row">
|
||||
<div className="col-lg-6 m-auto">
|
||||
<div className="heading1 text-center">
|
||||
<h1>Recent Memories</h1>
|
||||
<div className="space20" />
|
||||
<Link href="/">
|
||||
Home <i className="fa-solid fa-angle-right" /> <span>Recent Memories</span>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Gallery Section */}
|
||||
<div className="bloginner-section-area sp4">
|
||||
<div className="container">
|
||||
<div className="row">
|
||||
<div className="col-lg-12 m-auto">
|
||||
<div className="event2-header heading5 space-margin60">
|
||||
<h2 className="text-anime-style-3">
|
||||
Photos Gallery
|
||||
</h2>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="row gx-5">
|
||||
<div className="col-lg-12">
|
||||
<div className="row mt-4">
|
||||
{eventImages.map((image, index) => (
|
||||
<div
|
||||
key={image.id}
|
||||
className="col-lg-3 col-md-6 mb-4"
|
||||
data-aos="zoom-in"
|
||||
data-aos-duration={1000}
|
||||
>
|
||||
<div className="blog4-boxarea">
|
||||
<div
|
||||
className="img1"
|
||||
style={{ cursor: 'pointer' }}
|
||||
onClick={() => handleImageClick(index)}
|
||||
>
|
||||
<img
|
||||
src={image.src}
|
||||
alt={image.title || `gallery-${index}`}
|
||||
loading="lazy"
|
||||
style={{ width: '100%', height: 'auto' }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="bloginner-section-area sp4">
|
||||
<div className="container">
|
||||
<div className="row">
|
||||
<div className="col-lg-12 m-auto">
|
||||
<div className="event2-header heading5 space-margin60">
|
||||
<h2 className="text-anime-style-3">
|
||||
{matchedEvent?.title || "Photos Gallery"}
|
||||
<p>{matchedEvent?.desc}</p>
|
||||
</h2>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
<div className="row gx-5">
|
||||
<div className="col-lg-12">
|
||||
<div className="row mt-4">
|
||||
{galleryImages.map((src: string, index: number) => (
|
||||
<div
|
||||
key={index}
|
||||
className="col-lg-3 col-md-6 mb-4"
|
||||
data-aos="zoom-in"
|
||||
data-aos-duration={1000}
|
||||
>
|
||||
<div className="blog4-boxarea">
|
||||
<div
|
||||
className="img1"
|
||||
style={{ cursor: 'pointer' }}
|
||||
onClick={() => handleImageClick(index)}
|
||||
>
|
||||
<img
|
||||
src={src}
|
||||
alt={`gallery-${index}`}
|
||||
loading="lazy"
|
||||
style={{ width: '100%', height: 'auto' }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{eventImages.length === 0 && (
|
||||
<div className="col-12 text-center mt-5">
|
||||
<p className="text-muted">No images found for this event.</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{galleryImages.length === 0 && (
|
||||
<div className="col-12 text-center mt-5">
|
||||
<p className="text-muted">No images found for this event.</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Lightbox
|
||||
open={open}
|
||||
close={() => setOpen(false)}
|
||||
index={currentIndex}
|
||||
slides={galleryImages.map((src) => ({ src }))}
|
||||
/>
|
||||
</Layout>
|
||||
</>
|
||||
);
|
||||
{/* Lightbox */}
|
||||
<Lightbox
|
||||
open={open}
|
||||
close={() => setOpen(false)}
|
||||
index={currentIndex}
|
||||
slides={eventImages.map((img) => ({ src: img.src, title: img.title }))}
|
||||
/>
|
||||
</Layout>
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user