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

EmbedCard improvements #4503

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

EmbedCard improvements #4503

wants to merge 11 commits into from

Conversation

patrickpatrickpatrick
Copy link
Contributor

@patrickpatrickpatrick patrickpatrickpatrick commented Feb 24, 2025

If `IntersectionObserver` is not supported by the browser (it's not
present on `window`) then don't run the `IntersectionObserver` code in
`application.mjs` to enable lazy-load of the Youtube embeds. Instead,
the fallback (linking to the Youtube video) will be used.
@patrickpatrickpatrick patrickpatrickpatrick changed the title yt embed improve EmbedCard improvements Feb 24, 2025
Copy link

netlify bot commented Feb 24, 2025

You can preview this change here:

Name Link
🔨 Latest commit 8a93428
🔍 Latest deploy log https://app.netlify.com/sites/govuk-design-system-preview/deploys/67c1dd20219ba10008b249a9
😎 Deploy Preview https://deploy-preview-4503--govuk-design-system-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@patrickpatrickpatrick patrickpatrickpatrick force-pushed the yt-embed-improve branch 3 times, most recently from 5a892a3 to c711114 Compare February 25, 2025 13:59
@patrickpatrickpatrick patrickpatrickpatrick marked this pull request as ready for review February 25, 2025 14:33
@patrickpatrickpatrick patrickpatrickpatrick changed the title EmbedCard improvements EmbedCard improvements Feb 25, 2025
Copy link
Member

@romaricpascal romaricpascal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheers for making these updates, I think it's getting there, just noticed a couple of little things as I went through 🙌🏻

@@ -113,6 +113,9 @@ class CookieBanner extends ConfigurableComponent {
// Hide banner and show confirmation message
this.$cookieMessage.setAttribute('hidden', 'true')
this.revealConfirmationMessage(this.$cookieConfirmationAccept)

// Dispatch custom event to notify listening components of change
document.dispatchEvent(new CustomEvent('cookieChange'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌🏻 I like that as an option to let the cookie banner make other parts of the page aware cookies were accepted.

if (userConsent && userConsent.campaign) {
addEmbedCardObservers($embedCards)
} else {
document.addEventListener('cookieChange', function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isssue This will also trigger when the cookies are rejected, as the event is also fired in rejectCookies. Given we're now only setting up observers if cookies are accepted, I propose:

  • not dispatching an event in rejectCookies as we have no code responding to that
  • renaming the event in acceptCookies to cookieAccepted (in case we need a cookieRejected in the future)

@@ -440,6 +440,6 @@ pre .language-plaintext {
}
}

.app-campaign-cookie-banner .govuk-grid-column-two-thirds {
.app-campaign-cookie-banner div {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue div is quite generic and we risk side effects from this selector. I've asked on Slack for other ideas to avoid contradicting two-thirds in the name with 100% in the properties.

@@ -47,11 +41,6 @@ ignoreInSitemap: true
{% call embedCard({
ytId: "x91MPoITQ3I",
transcriptHref: "https://www.google.com",
authorImgSrc: "/images/dsd24-day1-speakers1.png",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue Could we have a second embed card that shows the author image, and possibly a test using it if there's none already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added another template, seems difficult to determine intersection in puppeteer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that's a shame, that would have allowed us to automatically test the IntersectionObserver worked as well 😔 Is it a lack of native methods from Puppeteer for triggering the intersection (if it is we can maybe try with native DOM methods like scrollIntoView) or just more general issues with IntersectionObserver?

- EmbedCard initialisation moved to `embed-initialisation.mjs`
- Fire `cookieChange` event when user accepts/rejects cookies
- Add `IntersectionObserver` if user has accepted cookies already
or if user accepts cookies on current page
@patrickpatrickpatrick patrickpatrickpatrick force-pushed the yt-embed-improve branch 2 times, most recently from 73f9e07 to 127c76c Compare February 28, 2025 15:06
Instead of creating the new element, appending the new element and then
deleting the placeholder element. Now we replace the placeholder with
the new element instead of deleting the placeholder explicitly.
Remove confusing `.app-campaign-cookie-banner
.govuk-grid-column-two-thirds` selector and replace with `div`.
Remove previous page for testing that was a draft of a Design System Day
promotion page. Add new `embed-test` page specifically for testing
`EmbedCard` and cookies.
If thumbnail image fails to load in the EmbedCard placeholder, it will
no longer collapse the size of the placeholder link.
YouTube Thumbnail API sets cookies so use a thumbnail image from the
application itself instead.
Copy link
Member

@romaricpascal romaricpascal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheers for the updates. Noticed two extra things that I didn't spot in the previous review, sorry 😔

@@ -113,6 +113,9 @@ class CookieBanner extends ConfigurableComponent {
// Hide banner and show confirmation message
this.$cookieMessage.setAttribute('hidden', 'true')
this.revealConfirmationMessage(this.$cookieConfirmationAccept)

// Dispatch custom event to notify listening components of change
document.dispatchEvent(new CustomEvent('cookieAccepted'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue Something I didn't think about with the first comment, sorry, is that there might be two cookie banners on the page (the top one and the one for the videos). We need to distinguish which cookies have been accepted in that event, as videos can only be enabled if the campaign cookie was accepted.

subtree: true
})
}
embedCardsInitialisation()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick For consistency with createAll we should probably write this as initialiseEmbedCards (active verb rather than a noun).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants