import variables from 'config/variables'; import { useState, memo, useEffect, useCallback } from 'react'; import { MdInfo, MdLocationOn } from 'react-icons/md'; import Modal from 'react-modal'; import { ShareModal } from 'components/Elements'; import ExcludeModal from './ExcludeModal'; import InformationItems from './InformationItems'; import ActionButtons from './ActionButtons'; import UnsplashStats from './UnsplashStats'; function PhotoInformation({ info, url, api }) { const [width, setWidth] = useState(0); const [height, setHeight] = useState(0); const [usePhotoMap, setPhotoMap] = useState(false); const [shareModal, openShareModal] = useState(false); const [excludeModal, openExcludeModal] = useState(false); const [favouriteTooltipText, setFavouriteTooltipText] = useState( variables.getMessage('widgets.quote.favourite'), ); useEffect(() => { const img = new Image(); img.onload = (event) => { setWidth(event.target.width); setHeight(event.target.height); }; img.src = url; }, [url]); const photoMap = useCallback(() => { if ( localStorage.getItem('photoMap') !== 'true' || !info.latitude || !info.longitude || usePhotoMap === false ) { return null; } const tile = `${variables.constants.API_URL}/map?latitude=${info.latitude}&longitude=${info.longitude}`; return ( location ); }, [info.latitude, info.longitude, usePhotoMap]); if (info.hidden === true || !info.credit) { return null; } let credit = info.credit; let photo = variables.getMessage('widgets.background.credit'); if (info.photographerURL && info.photographerURL !== '' && !info.offline && api) { photo = ( {photo} ); credit = ( {info.credit} ); } if (localStorage.getItem('photoInformation') === 'false') { return (
{credit} {info.location} {info.camera} {width}x{height}
); } let photoMapClassList = 'map-concept'; if (photoMap() !== null) { photoMapClassList += ' photoMap'; } const widgetStyle = localStorage.getItem('widgetStyle'); return (
openShareModal(false)} > openShareModal(false)} /> openExcludeModal(false)} > openExcludeModal(false)} /> {widgetStyle === 'legacy' && (
{photo} {credit}
)} {widgetStyle !== 'legacy' && (
{photoMap()}
{photoMap() && (
{' '} © Mapbox{' '} {' '} •{' '} {' '} © OpenStreetMap{' '} {' '} •{' '} {' '} Improve this map{' '}
)}
{info.description?.length > 40 ? `${info.description.substring(0, 40)}...` : info.location?.split(',').slice(-2).join(', ').trim()} {photo} {credit}
{info.views && info.downloads !== null && }
{variables.getMessage('widgets.background.information')}
)}
); } export default memo(PhotoInformation);