Skip to content

Commit

Permalink
Update LazyImage.js (#178)
Browse files Browse the repository at this point in the history
Lazy image was returning MEDIUM when ORIGINAL was needed
  • Loading branch information
gmcauliffe authored Oct 26, 2023
1 parent eef0d25 commit 3f86c78
Showing 1 changed file with 17 additions and 32 deletions.
49 changes: 17 additions & 32 deletions src/components/LazyImage/LazyImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,17 @@ function LazyImage({ alt, imageObject, bgColor, height, width, imgStyling }) {
}
}, [])

let src = ''

switch (width) {
case width <= 100:
src = getMediaPath({
mediaObject: imageObject,
type: IMAGE,
size: THUMBNAIL,
})
break
case width > 100 && width <= 560:
src = getMediaPath({
mediaObject: imageObject,
type: IMAGE,
size: SMALL,
})
break
case width > 1000:
src = getMediaPath({
mediaObject: imageObject,
type: IMAGE,
size: ORIGINAL,
})
break
case width > 560 && width <= 1000:
default:
src = getMediaPath({
mediaObject: imageObject,
type: IMAGE,
size: MEDIUM,
})
break
const getSize = () => {
if (width <= 100) {
return THUMBNAIL
}
if (width <= 560) {
return SMALL
}
if (width <= 1000) {
return MEDIUM
}
return ORIGINAL
}

const placeholder =
Expand All @@ -57,6 +36,12 @@ function LazyImage({ alt, imageObject, bgColor, height, width, imgStyling }) {

const aspectRatio = width / height

const src = getMediaPath({
mediaObject: imageObject,
type: IMAGE,
size: getSize(),
})

return (
<div className={`relative overflow-hidden ${imgStyling}`}>
<div style={{ paddingBottom: `${100 / aspectRatio}%` }} />
Expand Down

0 comments on commit 3f86c78

Please sign in to comment.