diff --git a/frontend/src/pages/StatePage.jsx b/frontend/src/pages/StatePage.jsx index 20d6d08..f05ea04 100644 --- a/frontend/src/pages/StatePage.jsx +++ b/frontend/src/pages/StatePage.jsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState, useRef } from "react"; +import React, { useEffect, useState } from "react"; import { useParams, Link } from "react-router-dom"; import { motion } from "framer-motion"; import { getStateBySlug } from "../lib/knowIndia"; @@ -14,15 +14,17 @@ import { UserCheck, Languages, Award, Building, Navigation } from "lucide-react"; +const PLACES_PER_PAGE = 12; + const StatePage = () => { const { stateName } = useParams(); const [stateData, setStateData] = useState(null); const [places, setPlaces] = useState([]); const [loading, setLoading] = useState(true); const [isDescriptionExpanded, setIsDescriptionExpanded] = useState(false); + const [placesPage, setPlacesPage] = useState(1); const { theme } = useTheme(); const isDark = theme === 'dark'; - const placesScrollRef = useRef(null); // Function to truncate text by word count const truncateByWords = (text, wordLimit) => { @@ -87,7 +89,12 @@ const StatePage = () => { }; fetchData(); }, [stateName]); - + + // Reset to page 1 when state or places change + useEffect(() => { + setPlacesPage(1); + }, [stateName, places.length]); + const displayStateName = stateName.split("-").map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(" "); // SEO: Update meta tags when state data is loaded @@ -108,13 +115,6 @@ const StatePage = () => { } }, [stateData, displayStateName, loading]); - const scrollPlaces = (direction) => { - if (placesScrollRef.current) { - const scrollAmount = 400; - placesScrollRef.current.scrollBy({ left: direction === 'left' ? -scrollAmount : scrollAmount, behavior: 'smooth' }); - } - }; - // Loading if (loading) { return ( @@ -587,188 +587,117 @@ const StatePage = () => { {places.length > 0 && (
-
- -

- - Explore Places -

- - {places.length} - -
-
- - -
-
- - {/* Horizontal Scroll */} -
- {places.map((place, index) => ( - - - {/* Image Container */} -
- {place.images?.[0] ? ( - {`${place.name} - ) : ( -
- -
- )} - - {/* Category Badge */} -
- - {place.category_name} - -
- - {/* Bookmark Button */} -
- -
-
- - {/* Content */} -
-

- {place.name} -

-

- {place.description} -

-
- -
- ))} -
+

+ + Explore Places +

+ + {places.length} + + - {/* View All Places Grid */} - {places.length > 4 && ( -
-

- All Destinations -

-
- {places.map((place, index) => ( - - { + const totalPages = Math.ceil(places.length / PLACES_PER_PAGE); + const start = (placesPage - 1) * PLACES_PER_PAGE; + const paginatedPlaces = places.slice(start, start + PLACES_PER_PAGE); + return ( + <> +
+ {paginatedPlaces.map((place, index) => ( + + +
+ {place.images?.[0] ? ( + {`${place.name} + ) : ( +
+ +
+ )} +
+
+ {place.category_name} +

{place.name}

+

{place.description}

+
+
+ + +
+ +
+ ))} +
+ + {/* Pagination */} + {totalPages > 1 && ( +
+
-
- )} + + + + Page {placesPage} of {totalPages} + + +
+ )} + + ); + })()}
)}