2020-10-17 09:47:01 +00:00
|
|
|
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';
|
2021-04-07 21:19:46 +00:00
|
|
|
import Download from '@material-ui/icons/GetApp';
|
2020-10-17 09:47:01 +00:00
|
|
|
|
2021-04-07 09:57:28 +00:00
|
|
|
const toDataURL = async (url) => {
|
2021-04-11 14:53:11 +00:00
|
|
|
const res = await fetch(url);
|
|
|
|
return URL.createObjectURL(await res.blob());
|
2021-04-08 18:52:17 +00:00
|
|
|
};
|
2021-04-07 09:57:28 +00:00
|
|
|
|
|
|
|
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);
|
2021-06-30 10:27:54 +00:00
|
|
|
window.stats.postEvent('feature', 'Background download');
|
2021-04-08 18:52:17 +00:00
|
|
|
};
|
2021-04-07 09:57:28 +00:00
|
|
|
|
2021-01-17 18:07:26 +00:00
|
|
|
export default function PhotoInformation(props) {
|
2021-03-19 22:30:29 +00:00
|
|
|
const language = window.language.widgets.background;
|
|
|
|
|
2021-04-14 11:51:11 +00:00
|
|
|
if (props.info.hidden === true || !props.info.credit) {
|
2021-03-21 13:19:24 +00:00
|
|
|
return null;
|
|
|
|
}
|
2021-03-21 13:09:06 +00:00
|
|
|
|
2021-05-06 16:30:13 +00:00
|
|
|
// remove unsplash and pexels text
|
2021-04-30 21:49:04 +00:00
|
|
|
const photographer = props.info.credit.split(` ${language.unsplash}`)[0].split(` ${language.pexels}`);
|
2021-04-27 13:52:04 +00:00
|
|
|
|
|
|
|
let credit = props.info.credit;
|
|
|
|
let photo = language.credit;
|
|
|
|
|
2021-05-06 16:30:13 +00:00
|
|
|
// unsplash and pexels credit
|
|
|
|
if (props.info.photographerURL && props.info.photographerURL !== '' && !props.info.offline && props.api) {
|
|
|
|
if (props.api === 'unsplash') {
|
2021-05-06 17:30:57 +00:00
|
|
|
photo = <a href={props.info.photoURL + '?utm_source=mue'} target='_blank' rel='noopener noreferrer'>{language.credit}</a>;
|
2021-05-06 16:30:13 +00:00
|
|
|
credit = <><a href={props.info.photographerURL} target='_blank' rel='noopener noreferrer'>{photographer}</a> <a href='https://unsplash.com?utm_source=mue' target='_blank' rel='noopener noreferrer'>{language.unsplash}</a></>;
|
|
|
|
} else {
|
2021-05-06 17:30:57 +00:00
|
|
|
photo = <a href={props.info.photoURL} target='_blank' rel='noopener noreferrer'>{language.credit}</a>;
|
2021-05-06 16:30:13 +00:00
|
|
|
credit = <><a href={props.info.photographerURL} target='_blank' rel='noopener noreferrer'>{photographer}</a> <a href='https://pexels.com' target='_blank' rel='noopener noreferrer'>{language.pexels}</a></>;
|
|
|
|
}
|
2021-04-27 13:52:04 +00:00
|
|
|
}
|
|
|
|
|
2021-01-17 16:25:21 +00:00
|
|
|
return (
|
2021-04-12 10:45:33 +00:00
|
|
|
<div className='photoInformation'>
|
2021-04-27 13:52:04 +00:00
|
|
|
<h1>{photo} <span id='credit'>{credit}</span></h1>
|
2021-05-09 15:37:28 +00:00
|
|
|
{localStorage.getItem('photoInformation') !== 'false' ? <><Info className='photoInformationHover'/>
|
|
|
|
<div className={props.className || 'infoCard'}>
|
|
|
|
<Info className='infoIcon'/>
|
|
|
|
<h1>{language.information}</h1>
|
|
|
|
<hr/>
|
|
|
|
<Location/>
|
|
|
|
<span id='infoLocation'>{props.info.location || 'N/A'}</span>
|
|
|
|
<Camera/>
|
|
|
|
<span id='infoCamera'>{props.info.camera || 'N/A'}</span>
|
|
|
|
<Resolution/>
|
|
|
|
<span id='infoResolution'>{props.info.resolution || 'N/A'}</span>
|
|
|
|
<Photographer/>
|
|
|
|
<span>{photographer}</span>
|
|
|
|
{(localStorage.getItem('downloadbtn') === 'true') && !props.info.offline && !props.info.photographerURL ?
|
|
|
|
<>
|
|
|
|
<Download/>
|
|
|
|
<span className='download' onClick={() => downloadImage(props.info)}>{language.download}</span>
|
|
|
|
</> : null}
|
|
|
|
</div>
|
|
|
|
</>: null}
|
2021-01-17 16:25:21 +00:00
|
|
|
</div>
|
|
|
|
);
|
2021-03-17 13:01:53 +00:00
|
|
|
}
|