feat(827): Added fallback on image if is error

This commit is contained in:
Pontus Dreij
2024-11-14 10:02:36 +01:00
parent f3037a1b3d
commit 38c48006be
2 changed files with 8 additions and 5 deletions

View File

@@ -27,16 +27,17 @@
.imagePlaceholder { .imagePlaceholder {
height: 100%; height: 100%;
min-height: 190px; min-height: 190px;
aspect-ratio: 16/9;
width: 100%; width: 100%;
background-color: #fff; background-color: #fff;
background-image: linear-gradient(45deg, #000000 25%, transparent 25%), background-image: linear-gradient(45deg, #000000 25%, transparent 25%),
linear-gradient(-45deg, #000000 25%, transparent 25%), linear-gradient(-45deg, #000000 25%, transparent 25%),
linear-gradient(45deg, transparent 75%, #000000 75%), linear-gradient(45deg, transparent 75%, #000000 75%),
linear-gradient(-45deg, transparent 75%, #000000 75%); linear-gradient(-45deg, transparent 75%, #000000 75%);
background-size: 160px 160px; background-size: 180px 180px;
background-position: background-position:
0 0, 0 0,
0 80px, 0 90px,
80px -80px, 90px -90px,
-80px 0; -90px 0;
} }

View File

@@ -20,9 +20,10 @@ export default function ImageGallery({
}: ImageGalleryProps) { }: ImageGalleryProps) {
const intl = useIntl() const intl = useIntl()
const [lightboxIsOpen, setLightboxIsOpen] = useState(false) const [lightboxIsOpen, setLightboxIsOpen] = useState(false)
const [imageError, setImageError] = useState(false)
const imageProps = fill ? { fill } : { height, width: height * 1.5 } const imageProps = fill ? { fill } : { height, width: height * 1.5 }
if (!images || images.length === 0) { if (!images || images.length === 0 || imageError) {
return <div className={styles.imagePlaceholder} /> return <div className={styles.imagePlaceholder} />
} }
@@ -38,6 +39,7 @@ export default function ImageGallery({
className={styles.image} className={styles.image}
src={images[0].imageSizes.medium} src={images[0].imageSizes.medium}
alt={images[0].metaData.altText} alt={images[0].metaData.altText}
onError={() => setImageError(true)}
{...imageProps} {...imageProps}
/> />
<div className={styles.imageCount}> <div className={styles.imageCount}>