From 410ca6cb772ff9e42050316543893ff16c32e0de Mon Sep 17 00:00:00 2001 From: Richard Hand Date: Thu, 25 Jul 2024 17:24:53 +0200 Subject: [PATCH] MWPW-155065 PartnerCards fallback for invalid thumbnail images - checks news card background image on first updated - replace with a hardcoded default image path - changes the background color of the card header to prevent FOUC --- edsdme/components/NewsCard.js | 24 +++++++++++++++++++++++- edsdme/components/PartnerCardsStyles.js | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/edsdme/components/NewsCard.js b/edsdme/components/NewsCard.js index ac8afaf..07c5657 100644 --- a/edsdme/components/NewsCard.js +++ b/edsdme/components/NewsCard.js @@ -1,9 +1,11 @@ import { newsCardStyles } from './PartnerCardsStyles.js'; -import { formatDate, getLibs } from '../scripts/utils.js'; +import { formatDate, getLibs, prodHosts } from '../scripts/utils.js'; const miloLibs = getLibs(); const { html, LitElement } = await import(`${miloLibs}/deps/lit-all.min.js`); +const DEFAULT_BACKGROUND_IMAGE_PATH = '/content/dam/solution/en/images/card-collection/sample_default.png'; + class NewsCard extends LitElement { static properties = { data: { type: Object } }; @@ -24,6 +26,26 @@ class NewsCard extends LitElement { return newUrl; } + checkBackgroundImage(element) { + const style = window.getComputedStyle(element); + const url = style.backgroundImage.slice(5, -2); + const img = new Image(); + + const isProd = prodHosts.includes(window.location.host); + const defaultBackgroundImageOrigin = `https://solutionpartners.${isProd ? '' : 'stage2.'}adobe.com`; + const defaultBackgroundImageUrl = `${defaultBackgroundImageOrigin}${DEFAULT_BACKGROUND_IMAGE_PATH}`; + + img.onerror = () => { + element.style.backgroundImage = `url(${defaultBackgroundImageUrl})`; + }; + + img.src = url; + } + + firstUpdated() { + this.checkBackgroundImage(this.shadowRoot.querySelector('.card-header')); + } + render() { return html`
diff --git a/edsdme/components/PartnerCardsStyles.js b/edsdme/components/PartnerCardsStyles.js index 5a5a975..14cf9a7 100644 --- a/edsdme/components/PartnerCardsStyles.js +++ b/edsdme/components/PartnerCardsStyles.js @@ -999,7 +999,7 @@ export const newsCardStyles = css` .news-card .card-header { min-height: 192px; max-height: 192px; - background-color: #323232; + background-color: #f5f5F5; background-repeat: no-repeat; background-position: 50% 50%; background-size: cover;