aboutsummaryrefslogtreecommitdiff
path: root/src/frontend/app/components/StopGallery.tsx
diff options
context:
space:
mode:
authorcopilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>2025-11-06 22:52:02 +0000
committerAriel Costas Guerrero <ariel@costas.dev>2025-11-07 10:47:20 +0100
commitee77f38cdb324cbcf12518490df77fc9e6b89282 (patch)
tree407f64a434291e1e375e6a1ccb55f59fa886a1ef /src/frontend/app/components/StopGallery.tsx
parente51cdd89afc08274ca622e18b8127feca29e90a3 (diff)
Improve gallery scroll indicators and format code
Co-authored-by: arielcostas <94913521+arielcostas@users.noreply.github.com>
Diffstat (limited to 'src/frontend/app/components/StopGallery.tsx')
-rw-r--r--src/frontend/app/components/StopGallery.tsx51
1 files changed, 35 insertions, 16 deletions
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<StopGalleryProps> = ({ stops, title, emptyMessage }) => {
+const StopGallery: React.FC<StopGalleryProps> = ({
+ stops,
+ title,
+ emptyMessage,
+}) => {
const scrollRef = useRef<HTMLDivElement>(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<StopGalleryProps> = ({ stops, title, emptyMessage })
<h2 className="page-subtitle">{title}</h2>
<span className="gallery-counter">{stops.length}</span>
</div>
-
- <motion.div
- className="gallery-scroll-container"
- ref={scrollRef}
- style={{ x }}
- >
+
+ <div className="gallery-scroll-container" ref={scrollRef}>
<div className="gallery-track">
{stops.map((stop) => (
<StopGalleryItem key={stop.stopId} stop={stop} />
))}
</div>
- </motion.div>
-
- <div className="gallery-indicators">
- {stops.map((_, index) => (
- <div key={index} className="gallery-indicator" />
- ))}
</div>
+
+ {stops.length > 1 && (
+ <div className="gallery-indicators">
+ {stops.map((_, index) => (
+ <div
+ key={index}
+ className={`gallery-indicator ${index === activeIndex ? "active" : ""}`}
+ />
+ ))}
+ </div>
+ )}
</div>
);
};