diff --git a/src/app/components/DirectorySlideshow.tsx b/src/app/components/DirectorySlideshow.tsx index 63a9991..b7ba68d 100644 --- a/src/app/components/DirectorySlideshow.tsx +++ b/src/app/components/DirectorySlideshow.tsx @@ -1,4 +1,5 @@ -import { useEffect, useState } from 'react'; +import { useEffect, useRef, useState } from 'react'; +import { ChevronLeft, ChevronRight, Pause, Play } from 'lucide-react'; import { listDirectory, getWebDAVBaseUrl, type EntryInfo } from '../webdav'; import { IMAGE_EXTS } from './MediaEntry'; @@ -7,8 +8,11 @@ interface Props { } export default function DirectorySlideshow({ path }: Props) { - const [images, setImages] = useState([]); - const [idx, setIdx] = useState(0); + const [images, setImages] = useState([]); + const [idx, setIdx] = useState(0); + const [paused, setPaused] = useState(false); + const [touched, setTouched] = useState(false); + const touchTimer = useRef | undefined>(undefined); useEffect(() => { if (!path) { setImages([]); return; } @@ -26,34 +30,70 @@ export default function DirectorySlideshow({ path }: Props) { }, [path]); useEffect(() => { - if (images.length <= 1) return; + if (images.length <= 1 || paused) return; const t = setInterval(() => setIdx(i => (i + 1) % images.length), 4000); return () => clearInterval(t); - }, [images.length]); + }, [images.length, paused]); + + useEffect(() => () => clearTimeout(touchTimer.current), []); if (images.length === 0) return null; const current = images[idx]; + const prev = () => setIdx(i => (i - 1 + images.length) % images.length); + const next = () => setIdx(i => (i + 1) % images.length); + + const handleTouch = () => { + setTouched(true); + clearTimeout(touchTimer.current); + touchTimer.current = setTimeout(() => setTouched(false), 3000); + }; + + const controlsVisible = touched ? 'opacity-100' : 'opacity-0 group-hover:opacity-100'; return (
- {current.name} - {images.length > 1 && ( -
- {images.map((_, i) => ( -
- )} +
+ {current.name} + + {images.length > 1 && ( + <> + {/* Prev / next */} +
+ + +
+ + {/* Dots + pause */} +
+ +
+ {images.map((_, i) => ( +
+
+ + )} +
); }