From dc75548abade5379d07099d8ffb1fd7aacb45eee Mon Sep 17 00:00:00 2001
From: Yuval Adam <_@yuv.al>
Date: Fri, 14 Nov 2025 08:56:02 +0100
Subject: Fix slider bug

---
 src/components/Geshem.tsx | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

(limited to 'src/components/Geshem.tsx')

diff --git a/src/components/Geshem.tsx b/src/components/Geshem.tsx
index c34cbc1..b235f6f 100644
--- a/src/components/Geshem.tsx
+++ b/src/components/Geshem.tsx
@@ -17,7 +17,7 @@ export function Geshem({ date }: GeshemProps) {
     (typeof window !== 'undefined' ? new URL(window.location.toString()).searchParams.get("history") : null) ||
     undefined
   );
-  const [slider, setSlider] = useState(playback ? PLAYBACK_SLOTS : 9);
+  const [slider, setSlider] = useState(0);
 
   useEffect(() => {
     const fetchImages = async () =>
@@ -55,11 +55,25 @@ export function Geshem({ date }: GeshemProps) {
     };
   }, [playback]);
 
+  // Update slider to point to the latest image when images change
+  useEffect(() => {
+    if (images.length > 0) {
+      setSlider(prevSlider => {
+        const maxIndex = playback ? PLAYBACK_SLOTS : images.length - 1;
+        // If this is the first load (slider is 0) or if slider is out of bounds, set to max
+        if (prevSlider === 0 || prevSlider > maxIndex) {
+          return maxIndex;
+        }
+        return prevSlider;
+      });
+    }
+  }, [images.length, playback]);
+
   return (
     <>
       <Map images={images} slider={slider} />
       <DateTime images={images} slider={slider} />
-      <Slider slider={slider} playback={playback} setSlider={setSlider} />
+      <Slider slider={slider} playback={playback} setSlider={setSlider} imageCount={images.length} />
     </>
   );
 }
\ No newline at end of file
-- 
cgit v1.3.1

