diff --git a/src/components/widgets/background/Favourite.jsx b/src/components/widgets/background/Favourite.jsx index b5e9812b..135ca575 100644 --- a/src/components/widgets/background/Favourite.jsx +++ b/src/components/widgets/background/Favourite.jsx @@ -29,12 +29,12 @@ export default class Favourite extends PureComponent { if (!url) { return; } - + localStorage.setItem('favourite', JSON.stringify({ url: url, credit: document.getElementById('credit').textContent, - location: document.getElementById('infoLocation').textContent, - camera: document.getElementById('infoCamera').textContent, + location: document.getElementById('infoLocation') ? document.getElementById('infoLocation').innerText : 'N/A', + camera: document.getElementById('infoCamera') ? document.getElementById('infoCamera').innerText : 'N/A', resolution: document.getElementById('infoResolution').textContent })); diff --git a/src/components/widgets/background/PhotoInformation.jsx b/src/components/widgets/background/PhotoInformation.jsx index f6e0521a..87a42f8a 100644 --- a/src/components/widgets/background/PhotoInformation.jsx +++ b/src/components/widgets/background/PhotoInformation.jsx @@ -6,11 +6,14 @@ const toDataURL = async (url) => { return URL.createObjectURL(await res.blob()); }; +const formatText = (text) => { + return text.toLowerCase().replaceAll(',', '').replaceAll(' ', '-'); +}; + 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`; + link.download = `mue-${formatText(info.credit)}-${formatText(info.location)}.jpg`; document.body.appendChild(link); link.click(); document.body.removeChild(link); @@ -74,10 +77,14 @@ export default function PhotoInformation(props) {

{language.information}


- - {props.info.location || 'N/A'} - - {props.info.camera || 'N/A'} + {props.info.location && props.info.location !== 'N/A' ? <> + + {props.info.location} + : null} + {props.info.camera && props.info.camera !== 'N/A' ? <> + + {props.info.camera} + : null} {width}x{height}