import React, { useState, useRef, useEffect } from "react"; import { ArrowButton} from "./ArrowButton"; export function FeedItemPhotos({ photos }: any) { const photoRef = useRef(0); const [photosX, setPhotosX] = useState(0); const [refLoaded, setRefLoaded] = useState(false); const [selectedPhoto, setSelectedPhoto] = useState(0); const [min_x, setMinX] = useState( -((((photoRef.current as any).width || 0) + 2) * (photos.length - 1)) ); useEffect(() => { if (photoRef) setRefLoaded(true); }, [photoRef]); useEffect(() => { if ((photoRef.current as any)?.width > 0) setMinX(-((((photoRef.current as any).width || 0) + 2) * (photos.length - 1))); }); const slideButtonEvent = (x: any) => { if (x < min_x) setPhotosX(min_x); else if (x > 0) setPhotosX(0); else setPhotosX(x); }; return (
{photosX !== 0 && ( { slideButtonEvent(photosX + ((photoRef.current as any).width || 0).width + 2); setSelectedPhoto(selectedPhoto - 1); }} /> )}
{" "} {refLoaded && photos.map((item: any, index: any) => { return ( index !== 0 && ( ) ); })}
{photosX !== min_x && photos.length > 1 && ( { slideButtonEvent(photosX - ((photoRef.current as any).width || 0).width - 2); setSelectedPhoto(selectedPhoto + 1); }} /> )} {photos.length > 1 && (
{photos.map((item: any, index: any) => { return (
); })}
)}
); }