Skip to content

Commit 33cdc9c

Browse files
authored
Merge pull request #14827 from guardian/doml/refactor-main-media-video
Refactor video in MainMedia type
2 parents 32e8a4c + 5c70793 commit 33cdc9c

27 files changed

+105
-73
lines changed

dotcom-rendering/fixtures/manual/trails.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export const trails: [
101101
},
102102
dataLinkName: 'news | group-0 | card-@2',
103103
mainMedia: {
104-
type: 'Video',
104+
type: 'YoutubeVideo',
105105
id: 'abcdef',
106106
videoId: 'abcd',
107107
title: 'some title',
@@ -316,7 +316,7 @@ export const trails: [
316316
headline: 'How plastics are invading our brain cells – video',
317317
dataLinkName: 'media | group-0 | card-@11',
318318
mainMedia: {
319-
type: 'Video',
319+
type: 'YoutubeVideo',
320320
id: '966acc06-a238-4d5f-b477-816eec0476f3',
321321
videoId: '4JUvvbpx2So',
322322
duration: 322,
@@ -408,7 +408,7 @@ export const trails: [
408408
dataLinkName: 'news | group-0 | card-@18',
409409
supportingContent: getSublinks(3),
410410
mainMedia: {
411-
type: 'Video',
411+
type: 'YoutubeVideo',
412412
id: 'abcdef',
413413
videoId: 'abcd',
414414
title: 'some title',
@@ -560,7 +560,7 @@ export const videoTrails: [DCRFrontCard, DCRFrontCard] = [
560560
"Amorim said the team proved by the victory against City that they 'can leave anyone outside the squad and manage to win'",
561561
webPublicationDate: '2024-12-16T15:21:02.000Z',
562562
mainMedia: {
563-
type: 'Video',
563+
type: 'YoutubeVideo',
564564
id: 'fa2ee832-c5e7-4305-8387-f0277d2d9e27',
565565
videoId: '9kIN--VV2LQ',
566566
duration: 117,
@@ -587,7 +587,7 @@ export const videoTrails: [DCRFrontCard, DCRFrontCard] = [
587587
'News Group Newspapers offered Harry ‘full and unequivocal apology’ for ‘serious intrusion’ by the paper',
588588
webPublicationDate: '2025-01-22T18:51:14.000Z',
589589
mainMedia: {
590-
type: 'Video',
590+
type: 'YoutubeVideo',
591591
id: '03ac0c90-3a66-448c-8562-b66a9ca9360e',
592592
videoId: '_2wsSKq6yAk',
593593
duration: 71,
@@ -655,7 +655,8 @@ export const loopVideoCard: DCRFrontCard = {
655655
headline: 'Headline for looping video card',
656656
trailText: 'Trail text for looping video card',
657657
mainMedia: {
658-
type: 'LoopVideo',
658+
type: 'SelfHostedVideo',
659+
videoStyle: 'Loop',
659660
atomId: '3cb22b60-2c3f-48d6-8bce-38c956907cce',
660661
sources: [
661662
{

dotcom-rendering/src/components/Caption.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export const WhenOverlaidWithStars = {
203203
export const ForVideos = {
204204
args: {
205205
...Standard.args,
206-
mediaType: 'Video',
206+
mediaType: 'YoutubeVideo',
207207
},
208208
parameters: {
209209
chromatic: {

dotcom-rendering/src/components/Caption.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,15 @@ export const Caption = ({
307307
shouldLimitWidth && limitedWidth,
308308
isOverlaid ? overlaidStyles(format) : bottomMarginStyles,
309309
isMainMedia &&
310-
(isBlog || mediaType === 'Video') &&
310+
(isBlog || mediaType === 'YoutubeVideo') &&
311311
tabletCaptionPadding,
312312
padCaption && captionPadding,
313313
isImmersive && immersivePadding,
314314
isGallery && galleryStyles,
315315
]}
316316
data-spacefinder-role="inline"
317317
>
318-
{mediaType === 'Video' ? (
318+
{mediaType === 'YoutubeVideo' ? (
319319
<VideoIcon format={format} />
320320
) : (
321321
<CameraIcon format={format} />

dotcom-rendering/src/components/Card/Card.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const aBasicLink = {
6161
};
6262

6363
const mainVideo: MainMedia = {
64-
type: 'Video',
64+
type: 'YoutubeVideo',
6565
id: '1234-abcdef-09876-xyz',
6666
videoId: '8M_yH-e9cq8',
6767
title: '’I care, but I don’t care’: Life after the Queen’s death | Anywhere but Westminster',

dotcom-rendering/src/components/Card/Card.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,13 @@ const getMedia = ({
279279
canPlayInline?: boolean;
280280
isBetaContainer: boolean;
281281
}) => {
282-
if (mainMedia?.type === 'LoopVideo' && canPlayInline) {
282+
if (mainMedia?.type === 'SelfHostedVideo' && canPlayInline) {
283283
return {
284284
type: 'loop-video',
285285
mainMedia,
286286
} as const;
287287
}
288-
if (mainMedia?.type === 'Video' && canPlayInline) {
288+
if (mainMedia?.type === 'YoutubeVideo' && canPlayInline) {
289289
return {
290290
type: 'youtube-video',
291291
mainMedia,
@@ -429,14 +429,16 @@ export const Card = ({
429429
* It is treated as a media card in the design system.
430430
*/
431431
const isVideoArticle =
432-
mainMedia?.type === 'Video' && format.design === ArticleDesign.Video;
432+
mainMedia?.type === 'YoutubeVideo' &&
433+
format.design === ArticleDesign.Video;
433434

434435
/**
435436
* Articles with a video as the main media but not classified as "video articles"
436437
* are styled differently and are not treated as media cards.
437438
*/
438439
const isVideoMainMedia =
439-
mainMedia?.type === 'Video' && format.design !== ArticleDesign.Video;
440+
mainMedia?.type === 'YoutubeVideo' &&
441+
format.design !== ArticleDesign.Video;
440442

441443
const isLabs = format.theme === ArticleSpecial.Labs;
442444

dotcom-rendering/src/components/Card/components/CardFooter.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const WithVideo = {
5555
args: {
5656
...WithAge.args,
5757
mainMedia: {
58-
type: 'Video',
58+
type: 'YoutubeVideo',
5959
duration: 972,
6060
},
6161
},

dotcom-rendering/src/components/Card/components/CardFooter.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ const labStyles = css`
5353
`;
5454

5555
type MainMedia =
56-
| { type: 'Video'; duration: number }
57-
| { type: 'LoopVideo'; duration: number }
56+
| { type: 'YoutubeVideo'; duration: number }
57+
| { type: 'SelfHostedVideo'; duration: number }
5858
| { type: 'Audio'; duration: string }
5959
| { type: 'Gallery'; count: string };
6060

@@ -85,7 +85,7 @@ export const CardFooter = ({
8585
return <footer css={labStyles}>{cardBranding}</footer>;
8686
}
8787

88-
if (mainMedia?.type === 'Video') {
88+
if (mainMedia?.type === 'YoutubeVideo') {
8989
return (
9090
<footer css={contentStyles}>
9191
<Pill

dotcom-rendering/src/components/FeatureCard.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ export const Video: Story = {
294294
altText: 'alt text',
295295
},
296296
mainMedia: {
297-
type: 'Video',
297+
type: 'YoutubeVideo',
298298
id: 'video-id',
299299
videoId: 'video-id',
300300
height: 1080,

dotcom-rendering/src/components/FeatureCard.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ const getMedia = ({
246246
mainMedia?: MainMedia;
247247
canPlayInline?: boolean;
248248
}) => {
249-
if (mainMedia && mainMedia.type === 'Video' && canPlayInline) {
249+
if (mainMedia && mainMedia.type === 'YoutubeVideo' && canPlayInline) {
250250
return {
251251
type: 'video',
252252
mainMedia,
@@ -383,11 +383,11 @@ export const FeatureCard = ({
383383
}: Props) => {
384384
const hasSublinks = supportingContent && supportingContent.length > 0;
385385

386-
const isVideoMainMedia = mainMedia?.type === 'Video';
386+
const isVideoMainMedia = mainMedia?.type === 'YoutubeVideo';
387387
const isVideoArticle = format.design === ArticleDesign.Video;
388388

389389
const videoDuration =
390-
mainMedia?.type === 'Video' ? mainMedia.duration : undefined;
390+
mainMedia?.type === 'YoutubeVideo' ? mainMedia.duration : undefined;
391391

392392
const media = getMedia({
393393
imageUrl: image?.src,
@@ -397,7 +397,7 @@ export const FeatureCard = ({
397397
});
398398

399399
const showYoutubeVideo =
400-
canPlayInline && showVideo && mainMedia?.type === 'Video';
400+
canPlayInline && showVideo && mainMedia?.type === 'YoutubeVideo';
401401

402402
const showCardAge =
403403
webPublicationDate !== undefined && showClock !== undefined;

dotcom-rendering/src/components/FlexibleGeneral.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ const liveUpdatesCard = {
261261
showQuotedHeadline: false,
262262
dataLinkName: 'news | group-0 | card-@1',
263263
mainMedia: {
264-
type: 'Video',
264+
type: 'YoutubeVideo',
265265
id: 'fd00c892-407f-4d99-adfb-a8d12eada25f',
266266
videoId: '04lLgC1NioA',
267267
height: 300,

0 commit comments

Comments
 (0)