From f91e05fca301952447cfb9b82ff41854d8d5a119 Mon Sep 17 00:00:00 2001 From: Aryan Kumar Date: Fri, 13 Feb 2026 00:16:29 +0530 Subject: [PATCH] Add pagination to FestivalsPage component, allowing users to navigate through festival listings. Implemented state management for current page and total pages, and updated rendering logic to display paginated results. --- frontend/src/pages/FestivalsPage.jsx | 75 +++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/FestivalsPage.jsx b/frontend/src/pages/FestivalsPage.jsx index 169cc20..a02d9a8 100644 --- a/frontend/src/pages/FestivalsPage.jsx +++ b/frontend/src/pages/FestivalsPage.jsx @@ -1,7 +1,7 @@ import { useState, useEffect } from "react"; import { Link } from "react-router-dom"; import { motion } from "framer-motion"; -import { Calendar, MapPin, Search, Filter, Sparkles, ChevronDown, Loader2, ArrowRight } from "lucide-react"; +import { Calendar, MapPin, Search, Filter, Sparkles, ChevronDown, Loader2, ArrowRight, ChevronLeft, ChevronRight } from "lucide-react"; import { useTheme } from "../context/ThemeContext"; import { getApiUrl } from "../config"; @@ -10,6 +10,8 @@ const MONTHS = [ 'July', 'August', 'September', 'October', 'November', 'December' ]; +const FESTIVALS_PER_PAGE = 9; + const FestivalsPage = () => { const { theme } = useTheme(); const isDark = theme === 'dark'; @@ -18,6 +20,7 @@ const FestivalsPage = () => { const [isLoading, setIsLoading] = useState(true); const [searchTerm, setSearchTerm] = useState(''); const [selectedMonth, setSelectedMonth] = useState(''); + const [currentPage, setCurrentPage] = useState(1); useEffect(() => { const fetchFestivals = async () => { @@ -38,6 +41,10 @@ const FestivalsPage = () => { fetchFestivals(); }, []); + useEffect(() => { + setCurrentPage(1); + }, [searchTerm, selectedMonth]); + const filteredFestivals = festivals.filter(festival => { const matchesSearch = !searchTerm || festival.name.toLowerCase().includes(searchTerm.toLowerCase()) || @@ -50,6 +57,14 @@ const FestivalsPage = () => { return matchesSearch && matchesMonth; }); + const totalPages = Math.max(1, Math.ceil(filteredFestivals.length / FESTIVALS_PER_PAGE)); + const startIndex = (currentPage - 1) * FESTIVALS_PER_PAGE; + const paginatedFestivals = filteredFestivals.slice(startIndex, startIndex + FESTIVALS_PER_PAGE); + + const goToPage = (page) => { + setCurrentPage(Math.max(1, Math.min(page, totalPages))); + }; + const truncateText = (text, maxLength = 300) => { if (text.length <= maxLength) return text; return text.substring(0, maxLength).trim() + '...'; @@ -147,6 +162,9 @@ const FestivalsPage = () => { {/* Results count */}
Showing {filteredFestivals.length} of {festivals.length} festivals + {filteredFestivals.length > FESTIVALS_PER_PAGE && ( + ยท Page {currentPage} of {totalPages} + )}
@@ -159,8 +177,9 @@ const FestivalsPage = () => {

Loading festivals...

) : filteredFestivals.length > 0 ? ( + <>
- {filteredFestivals.map((festival, index) => ( + {paginatedFestivals.map((festival, index) => ( { ))}
+ + {/* Pagination */} + {totalPages > 1 && ( + + +
+ {Array.from({ length: totalPages }, (_, i) => i + 1).map((page) => ( + + ))} +
+ +
+ )} + ) : (