Skip to content

Commit 4987472

Browse files
committed
Refactor feature card video
1 parent 599d5c8 commit 4987472

File tree

3 files changed

+36
-76
lines changed

3 files changed

+36
-76
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,7 @@ export const GalleryImmersive: Story = {
282282
},
283283
};
284284

285-
// A video article
286-
export const Video: Story = {
285+
export const YoutubeVideo: Story = {
287286
args: {
288287
format: {
289288
...cardProps.format,
@@ -308,17 +307,17 @@ export const Video: Story = {
308307
},
309308
};
310309

311-
export const VideoImmersive: Story = {
310+
export const YoutubeVideoImmersive: Story = {
312311
args: {
313-
...Video.args,
312+
...YoutubeVideo.args,
314313
...Immersive.args,
315314
},
316315
};
317316

318317
// A standard (non-video) article with a video main media
319-
export const VideoMainMedia: Story = {
318+
export const YoutubeVideoMainMedia: Story = {
320319
args: {
321-
...Video.args,
320+
...YoutubeVideo.args,
322321
image: {
323322
src: 'https://media.guim.co.uk/4612af5f4667888fa697139cf570b6373d93a710/2446_345_3218_1931/master/3218.jpg',
324323
altText: 'alt text',
@@ -330,9 +329,9 @@ export const VideoMainMedia: Story = {
330329
},
331330
};
332331

333-
export const VideoMainMediaImmersive: Story = {
332+
export const YoutubeVideoMainMediaImmersive: Story = {
334333
args: {
335-
...VideoMainMedia.args,
334+
...YoutubeVideoMainMedia.args,
336335
...Immersive.args,
337336
},
338337
};

dotcom-rendering/src/components/FeatureCard.tsx

Lines changed: 29 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ import {
55
space,
66
until,
77
} from '@guardian/source/foundations';
8-
import { Hide, SvgMediaControlsPlay } from '@guardian/source/react-components';
8+
import { Hide } from '@guardian/source/react-components';
99
import {
1010
ArticleDesign,
1111
type ArticleFormat,
1212
ArticleSpecial,
1313
} from '../lib/articleFormat';
14-
import { secondsToDuration } from '../lib/formatTime';
1514
import { getZIndex } from '../lib/getZIndex';
1615
import { getOphanComponents } from '../lib/labs';
1716
import { transparentColour } from '../lib/transparentColour';
@@ -39,7 +38,6 @@ import { FeatureCardCommentCount } from './FeatureCardCommentCount';
3938
import { FormatBoundary } from './FormatBoundary';
4039
import { Island } from './Island';
4140
import { MediaDuration } from './MediaDuration';
42-
import { Pill } from './Pill';
4341
import { StarRating } from './StarRating/StarRating';
4442
import { SupportingContent } from './SupportingContent';
4543
import { WaveForm } from './WaveForm';
@@ -218,12 +216,6 @@ const trailTextWrapper = css`
218216
}
219217
`;
220218

221-
const videoPillStyles = css`
222-
position: absolute;
223-
top: ${space[2]}px;
224-
right: ${space[2]}px;
225-
`;
226-
227219
const waveformStyles = css`
228220
position: absolute;
229221
bottom: 0;
@@ -239,16 +231,16 @@ const getMedia = ({
239231
imageUrl,
240232
imageAltText,
241233
mainMedia,
242-
canPlayInline,
234+
showVideo,
243235
}: {
244236
imageUrl?: string;
245237
imageAltText?: string;
246238
mainMedia?: MainMedia;
247-
canPlayInline?: boolean;
239+
showVideo?: boolean;
248240
}) => {
249-
if (mainMedia && mainMedia.type === 'YoutubeVideo' && canPlayInline) {
241+
if (mainMedia?.type === 'YoutubeVideo' && showVideo) {
250242
return {
251-
type: 'video',
243+
type: 'youtube-video',
252244
mainMedia,
253245
} as const;
254246
}
@@ -360,7 +352,7 @@ export const FeatureCard = ({
360352
imageLoading,
361353
showClock,
362354
mainMedia,
363-
canPlayInline,
355+
canPlayInline = false,
364356
kickerText,
365357
showPulsingDot,
366358
dataLinkName,
@@ -383,22 +375,15 @@ export const FeatureCard = ({
383375
}: Props) => {
384376
const hasSublinks = supportingContent && supportingContent.length > 0;
385377

386-
const isVideoMainMedia = mainMedia?.type === 'YoutubeVideo';
387378
const isVideoArticle = format.design === ArticleDesign.Video;
388379

389-
const videoDuration =
390-
mainMedia?.type === 'YoutubeVideo' ? mainMedia.duration : undefined;
391-
392380
const media = getMedia({
393381
imageUrl: image?.src,
394382
imageAltText: image?.altText,
395383
mainMedia,
396-
canPlayInline,
384+
showVideo: showVideo && canPlayInline,
397385
});
398386

399-
const showYoutubeVideo =
400-
canPlayInline && showVideo && mainMedia?.type === 'YoutubeVideo';
401-
402387
const showCardAge =
403388
webPublicationDate !== undefined && showClock !== undefined;
404389

@@ -413,11 +398,13 @@ export const FeatureCard = ({
413398

414399
const isLabs = format.theme === ArticleSpecial.Labs;
415400

401+
if (!media) return null;
402+
416403
return (
417404
<FormatBoundary format={format}>
418405
<ContainerOverrides containerPalette={containerPalette}>
419406
<div css={[baseCardStyles, hoverStyles, sublinkHoverStyles]}>
420-
{!showYoutubeVideo && (
407+
{media?.type !== 'youtube-video' && (
421408
<CardLink
422409
linkTo={linkTo}
423410
headlineText={headlineText}
@@ -426,7 +413,7 @@ export const FeatureCard = ({
426413
/>
427414
)}
428415
<div css={contentStyles}>
429-
{showYoutubeVideo && (
416+
{media?.type === 'youtube-video' && (
430417
<div
431418
data-chromatic="ignore"
432419
data-component="youtube-atom"
@@ -441,15 +428,15 @@ export const FeatureCard = ({
441428
defer={{ until: 'visible' }}
442429
>
443430
<YoutubeBlockComponent
444-
id={mainMedia.id}
445-
assetId={mainMedia.videoId}
431+
id={media.mainMedia.id}
432+
assetId={media.mainMedia.videoId}
446433
index={collectionId}
447-
expired={mainMedia.expired}
434+
expired={media.mainMedia.expired}
448435
format={format}
449436
stickyVideos={false}
450437
enableAds={false}
451-
duration={mainMedia.duration}
452-
posterImage={mainMedia.image}
438+
duration={media.mainMedia.duration}
439+
posterImage={media.mainMedia.image}
453440
width={300}
454441
height={375}
455442
origin="The Guardian"
@@ -481,7 +468,7 @@ export const FeatureCard = ({
481468
</Island>
482469
</div>
483470
)}
484-
{!showYoutubeVideo && media && (
471+
{media?.type !== 'youtube-video' && (
485472
<div
486473
css={css`
487474
position: relative;
@@ -490,24 +477,7 @@ export const FeatureCard = ({
490477
)};
491478
`}
492479
>
493-
{media.type === 'video' && (
494-
<div>
495-
<CardPicture
496-
mainImage={
497-
media.mainMedia.image ?? ''
498-
}
499-
imageSize={imageSize}
500-
alt={headlineText}
501-
loading={imageLoading}
502-
aspectRatio={aspectRatio}
503-
mobileAspectRatio={
504-
mobileAspectRatio
505-
}
506-
/>
507-
</div>
508-
)}
509-
510-
{media.type === 'picture' && (
480+
{media?.type === 'picture' && (
511481
<>
512482
<CardPicture
513483
mainImage={media.imageUrl}
@@ -519,7 +489,9 @@ export const FeatureCard = ({
519489
mobileAspectRatio
520490
}
521491
/>
522-
{isVideoMainMedia &&
492+
{isVideoArticle &&
493+
mainMedia?.type ===
494+
'YoutubeVideo' &&
523495
mainMedia.duration > 0 && (
524496
<MediaDuration
525497
mediaDuration={
@@ -684,7 +656,14 @@ export const FeatureCard = ({
684656
) : undefined
685657
}
686658
showLivePlayable={false}
687-
mainMedia={mainMedia}
659+
mainMedia={
660+
isVideoArticle &&
661+
mainMedia?.type ===
662+
'YoutubeVideo' &&
663+
mainMedia?.duration > 0
664+
? undefined
665+
: mainMedia
666+
}
688667
isNewsletter={isNewsletter}
689668
/>
690669

@@ -695,23 +674,6 @@ export const FeatureCard = ({
695674
233,
696675
)}
697676
</div>
698-
{/* On video article cards, the duration is displayed in the footer */}
699-
{!isVideoArticle &&
700-
isVideoMainMedia &&
701-
videoDuration !== undefined ? (
702-
<div css={videoPillStyles}>
703-
<Pill
704-
content={
705-
<time>
706-
{secondsToDuration(
707-
videoDuration,
708-
)}
709-
</time>
710-
}
711-
icon={<SvgMediaControlsPlay />}
712-
/>
713-
</div>
714-
) : null}
715677
</div>
716678

717679
{isImmersive &&

dotcom-rendering/src/components/StaticFeatureTwo.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ export const StaticFeatureTwo = ({
7474
isExternalLink={card.isExternalLink}
7575
branding={card.branding}
7676
containerPalette={containerPalette}
77-
trailText={undefined}
7877
serverTime={serverTime}
7978
imageLoading={imageLoading}
8079
aspectRatio={aspectRatio}

0 commit comments

Comments
 (0)