import React from 'react'; import Info from '@material-ui/icons/Info'; import Location from '@material-ui/icons/LocationOn'; import Camera from '@material-ui/icons/PhotoCamera'; import Resolution from '@material-ui/icons/Crop'; import Photographer from '@material-ui/icons/Person'; import Download from '@material-ui/icons/GetApp'; const toDataURL = async (url) => { const res = await fetch(url); return URL.createObjectURL(await res.blob()); }; const downloadImage = async (info) => { const link = document.createElement('a'); link.href = await toDataURL(info.url); // todo: make this a bit cleaner link.download = `mue-${info.credit.toLowerCase().replaceAll(' ', '-')}-${info.location.toLowerCase().replaceAll(',', '').replaceAll(' ', '-')}.jpg`; document.body.appendChild(link); link.click(); document.body.removeChild(link); }; export default function PhotoInformation(props) { const language = window.language.widgets.background; if (props.info.hidden === true || !props.info.credit) { return null; } // remove unsplash text const photographer = props.info.credit.split(` ${language.unsplash}`)[0].split(` ${language.pexels}`); let credit = props.info.credit; let photo = language.credit; // unsplash if (props.info.photographerURL && props.info.photographerURL !== '' && !props.info.offline) { photo = {language.credit}; credit = <>{photographer} {language.unsplash}; } return (

{photo} {credit}

{language.information}


{props.info.location || 'N/A'} {props.info.camera || 'N/A'} {props.info.resolution || 'N/A'} {photographer} {(localStorage.getItem('downloadbtn') === 'true') && !props.info.offline && !props.info.photographerURL ? <> downloadImage(props.info)}>{language.download} : null}
); }