From b8d30410358966c10ce5d9ca7c6a9873ae59937e Mon Sep 17 00:00:00 2001 From: Jaime Idolpx Date: Thu, 11 Jun 2026 12:52:32 -0400 Subject: [PATCH] feat(DirectorySlideshow): enhance slideshow controls with persistent pause state and improved index handling --- src/app/components/DirectorySlideshow.tsx | 40 ++++++++++++++--------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/app/components/DirectorySlideshow.tsx b/src/app/components/DirectorySlideshow.tsx index b7ba68d..daecf09 100644 --- a/src/app/components/DirectorySlideshow.tsx +++ b/src/app/components/DirectorySlideshow.tsx @@ -10,7 +10,7 @@ interface Props { export default function DirectorySlideshow({ path }: Props) { const [images, setImages] = useState([]); const [idx, setIdx] = useState(0); - const [paused, setPaused] = useState(false); + const [paused, setPaused] = useState(() => localStorage.getItem('slideshow.paused') === '1'); const [touched, setTouched] = useState(false); const touchTimer = useRef | undefined>(undefined); @@ -24,7 +24,8 @@ export default function DirectorySlideshow({ path }: Props) { return IMAGE_EXTS.has(ext); }); setImages(imgs); - setIdx(0); + const saved = parseInt(localStorage.getItem(`slideshow.idx:${path}`) ?? '0', 10); + setIdx(imgs.length > 0 ? Math.min(saved, imgs.length - 1) : 0); }) .catch(() => setImages([])); }, [path]); @@ -35,6 +36,11 @@ export default function DirectorySlideshow({ path }: Props) { return () => clearInterval(t); }, [images.length, paused]); + useEffect(() => { + if (images.length === 0) return; + localStorage.setItem(`slideshow.idx:${path}`, String(idx)); + }, [idx, path, images.length]); + useEffect(() => () => clearTimeout(touchTimer.current), []); if (images.length === 0) return null; @@ -73,23 +79,25 @@ export default function DirectorySlideshow({ path }: Props) { - {/* Dots + pause */} -
+ {/* Pause / play — centered */} +
-
- {images.map((_, i) => ( -
+
+ + {/* Dots */} +
+ {images.map((_, i) => ( +
)}