Skip to content

Commit 503658c

Browse files
Fix linting etc
1 parent 3af9a68 commit 503658c

File tree

4 files changed

+64
-34
lines changed

4 files changed

+64
-34
lines changed

dotcom-rendering/src/components/LoopVideoInArticle.importable.tsx

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { LoopVideo } from './LoopVideo.importable';
21
import type { ArticleFormat } from '../lib/articleFormat';
2+
import type { Source } from '../lib/video';
3+
import type { VideoAssets } from '../types/content';
34
import { Caption } from './Caption';
45
import type { Props as CardPictureProps } from './CardPicture';
5-
import type { Source } from '../lib/video';
6+
import { LoopVideo } from './LoopVideo.importable';
67
import type { SubtitleSize } from './LoopVideoPlayer';
78

89
type LoopVideoInArticleProps = {
10+
assets: VideoAssets[];
911
atomId: string;
1012
caption?: string;
1113
fallbackImage: CardPictureProps['mainImage'];
@@ -18,14 +20,36 @@ type LoopVideoInArticleProps = {
1820
isMainMedia: boolean;
1921
linkTo: string;
2022
posterImage: string;
21-
sources: Source[];
2223
uniqueId: string;
2324
width: number;
2425
subtitleSource?: string;
25-
subtitleSize: SubtitleSize;
26+
subtitleSize?: string;
27+
};
28+
29+
// The looping video player types its `sources` attribute as `Sources`
30+
// However, looping videos in articles are delivered as media atoms, which type their `assets` as `VideoAssets`
31+
// Which means that we need to alter the shape of the incoming `assets` to match the requirements of the outgoing `sources`
32+
const convertAssetsToSources = (assets: VideoAssets[]): Source[] => {
33+
return assets.map((asset) => {
34+
return {
35+
src: asset.url ?? '',
36+
mimeType: 'video/mp4',
37+
};
38+
});
39+
};
40+
41+
const convertSubtitleSize = (val?: string): SubtitleSize => {
42+
if (val == null) {
43+
return 'small' as SubtitleSize;
44+
}
45+
if (['small', 'medium', 'large'].includes(val)) {
46+
return val as SubtitleSize;
47+
}
48+
return 'small' as SubtitleSize;
2649
};
2750

2851
export const LoopVideoInArticle = ({
52+
assets,
2953
atomId,
3054
caption,
3155
fallbackImage,
@@ -38,36 +62,35 @@ export const LoopVideoInArticle = ({
3862
isMainMedia,
3963
linkTo,
4064
posterImage,
41-
sources,
65+
subtitleSize,
66+
subtitleSource,
4267
uniqueId,
4368
width = 500,
44-
subtitleSource,
45-
subtitleSize,
4669
}: LoopVideoInArticleProps) => {
4770
return (
4871
<>
4972
<LoopVideo
50-
sources={sources}
5173
atomId={atomId}
52-
uniqueId={uniqueId}
53-
height={height}
54-
width={width}
55-
posterImage={posterImage}
5674
fallbackImage={fallbackImage}
57-
fallbackImageSize={fallbackImageSize}
58-
fallbackImageLoading={fallbackImageLoading}
5975
fallbackImageAlt={fallbackImageAlt}
6076
fallbackImageAspectRatio={fallbackImageAspectRatio}
77+
fallbackImageLoading={fallbackImageLoading}
78+
fallbackImageSize={fallbackImageSize}
79+
height={height}
6180
linkTo={linkTo}
81+
posterImage={posterImage}
82+
sources={convertAssetsToSources(assets)}
83+
subtitleSize={convertSubtitleSize(subtitleSize)}
6284
subtitleSource={subtitleSource}
63-
subtitleSize={subtitleSize}
85+
uniqueId={uniqueId}
86+
width={width}
6487
/>
6588
{!!caption && (
6689
<Caption
6790
captionText={caption}
6891
format={format}
69-
mediaType="SelfHostedVideo"
7092
isMainMedia={isMainMedia}
93+
mediaType="SelfHostedVideo"
7194
/>
7295
)}
7396
</>

dotcom-rendering/src/components/VideoAtom.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import type { ArticleFormat } from '../lib/articleFormat';
2+
import type { VideoAssets } from '../types/content';
23
import { Caption } from './Caption';
34
import { MaintainAspectRatio } from './MaintainAspectRatio';
45

5-
type AssetType = {
6-
url: string;
7-
mimeType?: string;
8-
};
6+
// type AssetType = {
7+
// url: string;
8+
// mimeType?: string;
9+
// };
910

1011
interface Props {
1112
format: ArticleFormat;
12-
assets: AssetType[];
13+
assets: VideoAssets[];
1314
isMainMedia: boolean;
1415
poster?: string;
1516
caption?: string;

dotcom-rendering/src/lib/renderElement.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { Island } from '../components/Island';
2929
import { ItemLinkBlockElement } from '../components/ItemLinkBlockElement';
3030
import { KeyTakeaways } from '../components/KeyTakeaways';
3131
import { KnowledgeQuizAtom } from '../components/KnowledgeQuizAtom.importable';
32+
import { LoopVideoInArticle } from '../components/LoopVideoInArticle.importable';
3233
import { MainMediaEmbedBlockComponent } from '../components/MainMediaEmbedBlockComponent';
3334
import { MapEmbedBlockComponent } from '../components/MapEmbedBlockComponent.importable';
3435
import { MiniProfiles } from '../components/MiniProfiles';
@@ -74,8 +75,6 @@ import { ArticleDesign, type ArticleFormat } from './articleFormat';
7475
import type { EditionId } from './edition';
7576
import { getLargestImageSize } from './image';
7677

77-
import { LoopVideoInArticle } from '../components/LoopVideoInArticle.importable';
78-
7978
type Props = {
8079
format: ArticleFormat;
8180
element: FEElement;
@@ -508,27 +507,26 @@ export const renderElement = ({
508507
- But they will still be Media Atoms
509508
*/
510509

511-
if (element.videoPlayerFormat === 'Loop') {
512-
const updatedSources = element.assets.map((a) => ({
513-
src: a.src || a.url,
514-
mimeType: a.mimeType,
515-
}));
510+
if (element?.videoPlayerFormat === 'Loop') {
511+
const posterImageExists = !!element.posterImage?.[0]?.url;
516512
return (
517513
<>
518-
{element.posterImage?.[0]?.url && (
514+
{posterImageExists && (
519515
<Island
520516
priority="critical"
521517
defer={{ until: 'visible' }}
522518
>
523519
<LoopVideoInArticle
524-
sources={updatedSources}
520+
assets={element.assets}
525521
atomId={element.id}
526522
uniqueId={`${Math.random()}`}
527523
height={400}
528524
width={500}
529-
posterImage={element.posterImage?.[0]?.url}
525+
posterImage={
526+
element.posterImage?.[0]?.url ?? ''
527+
}
530528
fallbackImage={
531-
element.posterImage?.[0]?.url
529+
element.posterImage?.[0]?.url ?? ''
532530
}
533531
fallbackImageSize="small"
534532
fallbackImageLoading="lazy"
@@ -538,6 +536,8 @@ export const renderElement = ({
538536
format={format}
539537
caption={element.title}
540538
isMainMedia={isMainMedia}
539+
subtitleSize={element.subtitleSize}
540+
subtitleSource={element.subtitleSource}
541541
/>
542542
</Island>
543543
)}

dotcom-rendering/src/types/content.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,9 @@ interface LoopVideoInArticleElement {
422422
}[];
423423
title?: string;
424424
duration?: number;
425+
videoPlayerFormat?: string;
426+
subtitleSize?: string;
427+
subtitleSource?: string;
425428
}
426429

427430
export interface MapBlockElement extends ThirdPartyEmbeddedContent {
@@ -447,6 +450,9 @@ interface MediaAtomBlockElement {
447450
}[];
448451
title?: string;
449452
duration?: number;
453+
videoPlayerFormat?: string;
454+
subtitleSize?: string;
455+
subtitleSource?: string;
450456
}
451457

452458
export interface MultiImageBlockElement {
@@ -953,8 +959,8 @@ export interface Image {
953959
url: string;
954960
}
955961

956-
interface VideoAssets {
957-
url: string;
962+
export interface VideoAssets {
963+
url?: string;
958964
mimeType?: string;
959965
fields?: {
960966
source?: string;

0 commit comments

Comments
 (0)