Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alt image showing up in Firefox #708

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions client/src/pages/Tree/TreeImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ export const ImageLoad = React.memo(
<img
src={currentSrc}
style={{
opacity: loading ? 0.1 : 1,
opacity: loading ? 0 : 1,
transition: 'opacity .30s linear',
width: '100%',
}}
placeholder={placeholder}
alt={alt}
title={alt}
loading="lazy"
onError={(e) => (e.target.style = 'display: "none"')}
onError="this.onerror=null;"
/>
);
},
Expand All @@ -43,11 +44,18 @@ ImageLoad.displayName = 'ImageLoad';
// If the image has been downloaded, it will use the local file
// If not, it will use the image URL from the treeImages.json file
export const setFormatImagePath = (scientific) => {
if (!scientific || !treeImages[scientific]) return null;

if (
!scientific ??
!treeImages[scientific] ??
!treeImages[scientific].ImageURL
)
return null;
// replace spaces with hyphens for image path using regex
const scientificNospaces = scientific.toLowerCase().replace(/\s/g, '-');

const imagePath = `../../assets/images/data/${scientificNospaces}.jpg`;
const imagePath =
`../../assets/images/data/${scientificNospaces}.jpg` ??
treeImages[scientific].ImageURL ??
null;
return imagePath;
};