From ee77f38cdb324cbcf12518490df77fc9e6b89282 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 6 Nov 2025 22:52:02 +0000 Subject: Improve gallery scroll indicators and format code Co-authored-by: arielcostas <94913521+arielcostas@users.noreply.github.com> --- src/frontend/app/components/StopGallery.tsx | 51 ++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 16 deletions(-) (limited to 'src/frontend/app/components/StopGallery.tsx') diff --git a/src/frontend/app/components/StopGallery.tsx b/src/frontend/app/components/StopGallery.tsx index 7dda637..3646fdd 100644 --- a/src/frontend/app/components/StopGallery.tsx +++ b/src/frontend/app/components/StopGallery.tsx @@ -1,5 +1,4 @@ -import React, { useRef } from "react"; -import { motion, useMotionValue } from "framer-motion"; +import React, { useRef, useState, useEffect } from "react"; import { type Stop } from "../data/StopDataProvider"; import StopGalleryItem from "./StopGalleryItem"; import "./StopGallery.css"; @@ -10,9 +9,28 @@ interface StopGalleryProps { emptyMessage?: string; } -const StopGallery: React.FC = ({ stops, title, emptyMessage }) => { +const StopGallery: React.FC = ({ + stops, + title, + emptyMessage, +}) => { const scrollRef = useRef(null); - const x = useMotionValue(0); + const [activeIndex, setActiveIndex] = useState(0); + + useEffect(() => { + const element = scrollRef.current; + if (!element) return; + + const handleScroll = () => { + const scrollLeft = element.scrollLeft; + const itemWidth = element.scrollWidth / stops.length; + const index = Math.round(scrollLeft / itemWidth); + setActiveIndex(index); + }; + + element.addEventListener("scroll", handleScroll); + return () => element.removeEventListener("scroll", handleScroll); + }, [stops.length]); if (stops.length === 0 && emptyMessage) { return ( @@ -33,24 +51,25 @@ const StopGallery: React.FC = ({ stops, title, emptyMessage })

{title}

{stops.length} - - + +
{stops.map((stop) => ( ))}
- - -
- {stops.map((_, index) => ( -
- ))}
+ + {stops.length > 1 && ( +
+ {stops.map((_, index) => ( +
+ ))} +
+ )}
); }; -- cgit v1.3