2020-10-17 09:47:01 +00:00
|
|
|
import React from 'react';
|
2021-03-20 12:05:14 +00:00
|
|
|
|
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-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-04-27 13:52:04 +00:00
|
|
|
// remove unsplash 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-02 11:11:07 +00:00
|
|
|
// unsplash credit
|
2021-05-01 20:32:38 +00:00
|
|
|
if (props.info.photographerURL && props.info.photographerURL !== '' && !props.info.offline) {
|
2021-04-27 13:52:04 +00:00
|
|
|
photo = <a href={props.info.photoURL} target='_blank' rel='noopener noreferrer'>{language.credit}</a>;
|
|
|
|
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></>;
|
|
|
|
}
|
|
|
|
|
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-01-17 16:25:21 +00:00
|
|
|
<Info className='photoInformationHover'/>
|
|
|
|
<div className={props.className || 'infoCard'}>
|
|
|
|
<Info className='infoIcon'/>
|
2021-03-19 22:30:29 +00:00
|
|
|
<h1>{language.information}</h1>
|
2021-01-17 16:25:21 +00:00
|
|
|
<hr/>
|
|
|
|
<Location/>
|
2021-04-08 18:17:40 +00:00
|
|
|
<span>{props.info.location || 'N/A'}</span>
|
2021-01-17 16:25:21 +00:00
|
|
|
<Camera/>
|
2021-04-08 18:17:40 +00:00
|
|
|
<span>{props.info.camera || 'N/A'}</span>
|
2021-01-17 16:25:21 +00:00
|
|
|
<Resolution/>
|
2021-04-08 18:17:40 +00:00
|
|
|
<span>{props.info.resolution || 'N/A'}</span>
|
2021-01-17 16:25:21 +00:00
|
|
|
<Photographer/>
|
2021-04-27 13:52:04 +00:00
|
|
|
<span>{photographer}</span>
|
2021-04-28 13:25:24 +00:00
|
|
|
{(localStorage.getItem('downloadbtn') === 'true') && !props.info.offline && !props.info.photographerURL ?
|
2021-04-08 18:17:40 +00:00
|
|
|
<>
|
|
|
|
<Download/>
|
|
|
|
<span className='download' onClick={() => downloadImage(props.info)}>{language.download}</span>
|
|
|
|
</> : null}
|
2020-10-17 09:47:01 +00:00
|
|
|
</div>
|
2021-01-17 16:25:21 +00:00
|
|
|
</div>
|
|
|
|
);
|
2021-03-17 13:01:53 +00:00
|
|
|
}
|