fix: video not playing on thumb click

This commit is contained in:
Zamitto 2024-05-12 17:03:39 -03:00
parent 05c6c7c64d
commit 4302639220

View file

@ -33,10 +33,6 @@ export function GallerySlider({ gameDetails }: GallerySliderProps) {
const [arrowShow, setArrowShow] = useState(false); const [arrowShow, setArrowShow] = useState(false);
const showNextImage = () => { const showNextImage = () => {
if (currentVideoRef.current) {
currentVideoRef.current.pause()
}
setMediaIndex((index: number) => { setMediaIndex((index: number) => {
if (index === mediaCount - 1) return 0; if (index === mediaCount - 1) return 0;
@ -45,10 +41,6 @@ export function GallerySlider({ gameDetails }: GallerySliderProps) {
}; };
const showPrevImage = () => { const showPrevImage = () => {
if (currentVideoRef.current) {
currentVideoRef.current.pause()
}
setMediaIndex((index: number) => { setMediaIndex((index: number) => {
if (index === 0) return mediaCount - 1; if (index === 0) return mediaCount - 1;
@ -61,6 +53,10 @@ export function GallerySlider({ gameDetails }: GallerySliderProps) {
}, [gameDetails]); }, [gameDetails]);
useEffect(() => { useEffect(() => {
if (currentVideoRef.current) {
currentVideoRef.current.pause()
}
if (hasMovies && mediaContainerRef.current) { if (hasMovies && mediaContainerRef.current) {
mediaContainerRef.current.childNodes.forEach((node, index) => { mediaContainerRef.current.childNodes.forEach((node, index) => {
if (index == mediaIndex && node instanceof HTMLVideoElement) { if (index == mediaIndex && node instanceof HTMLVideoElement) {