import { FC, useEffect, useState } from 'react'; import { FaArrowLeft, FaArrowRight } from 'react-icons/fa'; import { GetUserProfile, IPhotoData, LocalizeText } from '../../../api'; import { Flex, Grid, Text } from '../../../common'; export interface CameraWidgetShowPhotoViewProps { currentIndex: number; currentPhotos: IPhotoData[]; } export const CameraWidgetShowPhotoView: FC = props => { const { currentIndex = -1, currentPhotos = null } = props; const [ imageIndex, setImageIndex ] = useState(0); const currentImage = (currentPhotos && currentPhotos.length) ? currentPhotos[imageIndex] : null; const next = () => { setImageIndex(prevValue => { let newIndex = (prevValue + 1); if(newIndex >= currentPhotos.length) newIndex = 0; return newIndex; }); } const previous = () => { setImageIndex(prevValue => { let newIndex = (prevValue - 1); if(newIndex < 0) newIndex = (currentPhotos.length - 1); return newIndex; }); } useEffect(() => { setImageIndex(currentIndex); }, [ currentIndex ]); if(!currentImage) return null; return ( { !currentImage.w && { LocalizeText('camera.loading') } } { currentImage.m && currentImage.m.length && { currentImage.m } } { (currentImage.n || '') } { new Date(currentImage.t * 1000).toLocaleDateString() } { (currentPhotos.length > 1) && GetUserProfile(currentImage.oi) }>{ currentImage.o } } ); }