Skip to content

Commit 19644a1

Browse files
committed
Reinstate LoopVideoInArticle
1 parent 6a2362a commit 19644a1

File tree

3 files changed

+65
-42
lines changed

3 files changed

+65
-42
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import type { ArticleFormat } from '../lib/articleFormat';
2+
import { convertAssetsToVideoSources, getSubtitleAsset } from '../lib/video';
3+
import type { MediaAtomBlockElement } from '../types/content';
4+
import { Caption } from './Caption';
5+
import { LoopVideo } from './LoopVideo.importable';
6+
7+
type LoopVideoInArticleProps = {
8+
element: MediaAtomBlockElement;
9+
format: ArticleFormat;
10+
isMainMedia: boolean;
11+
};
12+
13+
export const LoopVideoInArticle = ({
14+
element,
15+
format,
16+
isMainMedia,
17+
}: LoopVideoInArticleProps) => {
18+
const posterImageUrl = element.posterImage?.[0]?.url;
19+
const caption = element.title;
20+
21+
if (!posterImageUrl) {
22+
return null;
23+
}
24+
25+
return (
26+
<>
27+
<LoopVideo
28+
atomId={element.id}
29+
fallbackImage={posterImageUrl}
30+
fallbackImageAlt={caption}
31+
fallbackImageAspectRatio={'5:4'}
32+
fallbackImageLoading={'lazy'}
33+
fallbackImageSize={'small'}
34+
height={400}
35+
linkTo={'Article-embed-MediaAtomBlockElement'}
36+
posterImage={posterImageUrl}
37+
sources={convertAssetsToVideoSources(element.assets)}
38+
subtitleSize={'small'}
39+
subtitleSource={getSubtitleAsset(element.assets)}
40+
uniqueId={element.id}
41+
width={500}
42+
/>
43+
{!!caption && (
44+
<Caption
45+
captionText={caption}
46+
format={format}
47+
isMainMedia={isMainMedia}
48+
mediaType="SelfHostedVideo"
49+
/>
50+
)}
51+
</>
52+
);
53+
};

dotcom-rendering/src/lib/renderElement.tsx

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { AudioAtomWrapper } from '../components/AudioAtomWrapper.importable';
44
import { BlockquoteBlockComponent } from '../components/BlockquoteBlockComponent';
55
import { CalloutBlockComponent } from '../components/CalloutBlockComponent.importable';
66
import { CalloutEmbedBlockComponent } from '../components/CalloutEmbedBlockComponent.importable';
7-
import { Caption } from '../components/Caption';
87
import { CaptionBlockComponent } from '../components/CaptionBlockComponent';
98
import { CartoonComponent } from '../components/CartoonComponent';
109
import { ChartAtom } from '../components/ChartAtom.importable';
@@ -30,7 +29,7 @@ import { Island } from '../components/Island';
3029
import { ItemLinkBlockElement } from '../components/ItemLinkBlockElement';
3130
import { KeyTakeaways } from '../components/KeyTakeaways';
3231
import { KnowledgeQuizAtom } from '../components/KnowledgeQuizAtom.importable';
33-
import { LoopVideo } from '../components/LoopVideo.importable';
32+
import { LoopVideoInArticle } from '../components/LoopVideoInArticle.importable';
3433
import { MainMediaEmbedBlockComponent } from '../components/MainMediaEmbedBlockComponent';
3534
import { MapEmbedBlockComponent } from '../components/MapEmbedBlockComponent.importable';
3635
import { MiniProfiles } from '../components/MiniProfiles';
@@ -75,7 +74,6 @@ import type { FEElement, RoleType, StarRating } from '../types/content';
7574
import { ArticleDesign, type ArticleFormat } from './articleFormat';
7675
import type { EditionId } from './edition';
7776
import { getLargestImageSize } from './image';
78-
import { convertAssetsToVideoSources, getSubtitleAsset } from './video';
7977

8078
type Props = {
8179
format: ArticleFormat;
@@ -508,46 +506,18 @@ export const renderElement = ({
508506
- But they will still be Media Atoms
509507
*/
510508
if (element.videoPlayerFormat === 'Loop') {
511-
const posterImageUrl = element.posterImage?.[0]?.url;
512509
return (
513510
<>
514-
{!!posterImageUrl && (
515-
<Island
516-
priority="critical"
517-
defer={{ until: 'visible' }}
518-
>
519-
<>
520-
<LoopVideo
521-
atomId={element.id}
522-
fallbackImage={posterImageUrl}
523-
fallbackImageAlt={element.title}
524-
fallbackImageAspectRatio={'5:4'}
525-
fallbackImageLoading={'lazy'}
526-
fallbackImageSize={'small'}
527-
height={400}
528-
linkTo={''}
529-
posterImage={posterImageUrl}
530-
sources={convertAssetsToVideoSources(
531-
element.assets,
532-
)}
533-
subtitleSize={'small'}
534-
subtitleSource={getSubtitleAsset(
535-
element.assets,
536-
)}
537-
uniqueId={element.id}
538-
width={500}
539-
/>
540-
{!!element.title && (
541-
<Caption
542-
captionText={element.title}
543-
format={format}
544-
isMainMedia={isMainMedia}
545-
mediaType="SelfHostedVideo"
546-
/>
547-
)}
548-
</>
549-
</Island>
550-
)}
511+
<Island
512+
priority="critical"
513+
defer={{ until: 'visible' }}
514+
>
515+
<LoopVideoInArticle
516+
element={element}
517+
format={format}
518+
isMainMedia={isMainMedia}
519+
/>
520+
</Island>
551521
</>
552522
);
553523
} else {

dotcom-rendering/src/types/content.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ export interface MapBlockElement extends ThirdPartyEmbeddedContent {
423423
role?: RoleType;
424424
}
425425

426-
interface MediaAtomBlockElement {
426+
export interface MediaAtomBlockElement {
427427
_type: 'model.dotcomrendering.pageElements.MediaAtomBlockElement';
428428
elementId: string;
429429
id: string;

0 commit comments

Comments
 (0)