-
Notifications
You must be signed in to change notification settings - Fork 31
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
Support embedded Youtube Atom in Card #8075
Conversation
Size Change: -22.7 kB (-4%) Total Size: 622 kB
ℹ️ View Unchanged
|
fe71555
to
17bb65c
Compare
17bb65c
to
16b0ef7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Little code pointers below 👇
@@ -200,6 +200,7 @@ gen-schema: | |||
@git add src/model/article-schema.json | |||
@git add src/model/front-schema.json | |||
@git add src/model/block-schema.json | |||
@git add src/model/tag-front-schema.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small refactors since #7752 introduced the new schema
// Size fixed to a 5:3 ratio | ||
width: 500, | ||
height: 300, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cards do not have a concept of an intrinsic size, and calculating the size of the poster image seemed brittle.
16b0ef7
to
b747b27
Compare
26309b2
to
cf02622
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR looks great! Whilst it makes sense I got a bit confused.
Having two types for CardYoutubeVideo
seemed a little leaky, especially as the transformation for either type is at different stages of the rendering pipeline (enhance
vs cardWrappers.onlyKeepPlayIcon
).
I wonder if we could make it more explicit of what we're doing with fewer transformations and follow some existing naming?
Here's a little pseudo code as I think I've been a little muddy in my explanation:
type DCRCardType = {
// ...other props...
// assuming this flattening is done as we prefer flat
showMainVideo: FECardType.properties.showMainVideo;
// video - this is identical to the image prop
video = decideVideo(FECardType);
}
type FrontCard = {
// ...other props...
showVideo: DCRCardType.showMainVideo;
video: DCRCardType.video;
// Maybe this isn't size, but follows the same pattern as images
// This gets in `cardWrappers` as that's what is aware of this context
// it is existing also an explicit property, rather than a transformation to an existing property
// it also doesn't leak the `show-only-icon` to `CardYoutubeVideo`
videoSize: "unplayable" : "playable";
}
// Card.tsx
const Card = ({ showVideo, video, videoSize }) => {
if (video && showVideo) {
if (videoSize === "playable") <VideoPlayer />
if (videoSize === "unplayable") <PosterWithIcon />
} else {
// image logic
}
}
{image.type === 'mainMedia' && | ||
mainVideo?.type !== 'embedded-playable-video' && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be tempted to swap this around to make the logic more analogous to:
if (isPlayableVideo) {
<Youtube />
} else if (image = isMainMedia) {
<CardPicture />
}
Not sure if it's clearer just took my a couple seconds to work out what was going on.
{image.type === 'mainMedia' && | |
mainVideo?.type !== 'embedded-playable-video' && ( | |
{mainVideo?.type !== 'embedded-playable-video' && | |
image.type === 'mainMedia' && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering that too. Could not settle on a specific one so I’ll use your suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My reasoning is that they aren't different types, it is rather a condition set by the parent component which has extra context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f2538d7
to
d36891e
Compare
838a3aa
to
1257340
Compare
dotcom-rendering/src/types/front.ts
Outdated
expired?: boolean; | ||
activeVersion?: number; | ||
/** @deprecated */ | ||
channelId?: unknown; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are defaultHtml
and channelId
unknown and not string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on a similar question by @jamesgorrie I decided to remove them, but somehow forgot.
My thinking was that we knew these fields come through, but we are not currently using them in any meaningful way. I wanted to make it clear to future travellers. I’ll just comment them out for now.
6757511
to
b99c0c0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! You have a +1 from me, don't know if it's best to also get @jamesgorrie's approval as he made all these great suggestions. My only doubt is:
export type VideoSize = 'playable' | 'unplayable';
If we could name this something more relevant to the values it gets, that would be preferable but it's not a blocker.
alt={byline ?? ''} | ||
containerPalette={containerPalette} | ||
format={format} | ||
/> | ||
</AvatarContainer> | ||
)} | ||
{image.type === 'video' && ( | ||
<div | ||
data-chromatic="ignore" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chromatic will ignore the content of this element – ping @cemms1.
d96fdeb
to
591a366
Compare
Waiting on #7972 before merging cc @abeddow91 |
591a366
to
30da4a6
Compare
ea61540
to
1a01a5b
Compare
30da4a6
to
3b08554
Compare
3b08554
to
df5ac31
Compare
@@ -289,9 +309,7 @@ export type DCRFrontCard = { | |||
byline?: string; | |||
showByline?: boolean; | |||
avatarUrl?: string; | |||
mediaType?: MediaType; | |||
mediaDuration?: number; | |||
showMainVideo: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could not find examples of when we want to hide the main video, so have removed as a simplication step.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A fine example of a collaborative PR!
df5ac31
to
ba8703a
Compare
renamed the method as it can handle more than images we can narrow our types with a discriminated union
an empty array should result in no poster image available.
ba8703a
to
9ddf882
Compare
The settings comes from the facia-tool via Frontend, when “Show Video” is enabled for a trail in a container, it should be displayed as a playable video inline instead or redirecting to the article itself. Currently, only Youtube Atoms are supported. There is currently no guarantee that the first atom will be the expected video, but it happens to be the case the vast majority of the time A minimum Card width of one third or three columns is required for the YouTube atom to be embedded, similar to the existing Frontend logic: https://github.com/guardian/frontend/blob/1c4555a9f/common/app/layout/cards/CardType.scala#L20-L23
9ddf882
to
14f65ea
Compare
mediaDuration: | ||
faciaCard.properties.maybeContent?.elements.mediaAtoms[0] | ||
?.duration, | ||
showMainVideo: faciaCard.properties.showMainVideo, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrectly removing this caused #8227
/** For displaying embedded, playable videos directly in cards */ | ||
type Video = Media & { | ||
type: 'Video'; | ||
elementId: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not have been called elementId
but simply id
. It’s not the randomly generated frontend UUID, but rather a consistent value that uniquely identifies the main media atom.
Fix in #10218
What does this change?
Enables support for
showVideo
from facia-tool, which allows videos to be played inline/embedded directly on fronts. Previously, it would redirect to the article itself.A minimum Card width of one third or three columns is required for the YouTube atom to be embedded, similar to the existing Frontend logic.
Why?
Closes #6662
Known issues
There is currently no guarantee that the first atom will be the expected video, but it happens to be the case the vast majority of the time. See guardian/frontend#26247 for a possible fix.
Currently, only Youtube Atoms are supported.
Screenshots