Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion dotcom-rendering/src/components/Card/Card.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const basicCardProps: CardProps = {
altText: 'alt text',
},
mediaPositionOnDesktop: 'top',
showAge: true,
isExternalLink: false,
canPlayInline: true,
imageLoading: 'eager',
Expand Down
20 changes: 6 additions & 14 deletions dotcom-rendering/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export type Props = {
containerPalette?: DCRContainerPalette;
containerType?: DCRContainerType;
showAge?: boolean;
ageFormat?: 'relative' | 'absolute';
discussionApiUrl: string;
discussionId?: string;
isExternalLink: boolean;
Expand All @@ -140,7 +141,6 @@ export type Props = {
liveUpdatesPosition?: Position;
onwardsSource?: OnwardsSource;
showVideo?: boolean;
isTagPage?: boolean;
/** Allows the consumer to set the aspect ratio on the media */
aspectRatio?: AspectRatio;
/** The index of the card in a carousel */
Expand Down Expand Up @@ -402,6 +402,7 @@ export const Card = ({
containerPalette,
containerType,
showAge = true,
ageFormat = 'relative',
discussionApiUrl,
discussionId,
isCrossword,
Expand All @@ -415,7 +416,6 @@ export const Card = ({
onwardsSource,
showVideo = true,
serverTime,
isTagPage = false,
aspectRatio,
index = 0,
uniqueId = '',
Expand Down Expand Up @@ -456,26 +456,18 @@ export const Card = ({
const isLabs = format.theme === ArticleSpecial.Labs;

const decideAge = () => {
if (!webPublicationDate) return undefined;
const withinTwelveHours = isWithinTwelveHours(webPublicationDate);

const shouldShowAge =
isStorylines ||
isTagPage ||
!!onwardsSource ||
(showAge && withinTwelveHours);

if (!shouldShowAge) return undefined;
if (!webPublicationDate || !showAge) return undefined;

return (
<CardAge
webPublication={{
date: webPublicationDate,
isWithinTwelveHours: withinTwelveHours,
isWithinTwelveHours:
isWithinTwelveHours(webPublicationDate),
}}
isAbsolute={ageFormat === 'absolute'}
showClock={showClock}
serverTime={serverTime}
isTagPage={isTagPage}
/>
);
};
Expand Down
16 changes: 7 additions & 9 deletions dotcom-rendering/src/components/Card/components/CardAge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,22 @@ const ageStyles = (colour: string) => {
};

type Props = {
serverTime?: number;
webPublication: {
date: string;
isWithinTwelveHours: boolean;
};
isTagPage: boolean;
isAbsolute: boolean;
serverTime?: number;
showClock?: boolean;
colour?: string;
isStorylines?: boolean;
};

export const CardAge = ({
serverTime,
webPublication,
isTagPage,
isAbsolute,
serverTime,
showClock,
colour = palette('--card-footer-text'),
isStorylines,
}: Props) => {
if (timeAgo(new Date(webPublication.date).getTime()) === false) {
return null;
Expand All @@ -48,18 +46,18 @@ export const CardAge = ({
return (
<span css={ageStyles(colour)}>
{showClock && <ClockIcon />}
{isTagPage && !isStorylines ? (
{isAbsolute ? (
<DateTime
date={new Date(webPublication.date)}
display={'absolute'}
display="absolute"
showWeekday={false}
showDate={!webPublication.isWithinTwelveHours}
showTime={true}
/>
) : (
<DateTime
date={new Date(webPublication.date)}
display={'relative'}
display="relative"
serverTime={serverTime}
showWeekday={false}
showDate={true}
Expand Down
5 changes: 2 additions & 3 deletions dotcom-rendering/src/components/Carousel.island.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,8 @@ const CarouselCard = ({
webPublicationDate={webPublicationDate}
kickerText={kickerText}
image={image}
mediaSize={'carousel'}
mediaSize="carousel"
showClock={!isOnwardContent && true}
showAge={true}
showQuotedHeadline={format.design === ArticleDesign.Comment}
dataLinkName={dataLinkName}
discussionId={discussionId}
Expand All @@ -533,7 +532,7 @@ const CarouselCard = ({
index={index}
showTopBarDesktop={!isOnwardContent}
showTopBarMobile={!isOnwardContent}
aspectRatio={'5:4'}
aspectRatio="5:4"
/>
</LI>
);
Expand Down
14 changes: 7 additions & 7 deletions dotcom-rendering/src/components/DecideContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Props = {
imageLoading: NonNullable<ImgHTMLAttributes<unknown>['loading']>;
containerType: DCRContainerType;
containerPalette?: DCRContainerPalette;
showAge?: boolean;
hideAge: boolean;
serverTime?: number;
aspectRatio: AspectRatio;
sectionId: string;
Expand All @@ -39,7 +39,7 @@ export const DecideContainer = ({
groupedTrails,
containerType,
containerPalette,
showAge,
hideAge,
serverTime,
imageLoading,
aspectRatio,
Expand All @@ -65,7 +65,7 @@ export const DecideContainer = ({
<FlexibleSpecial
groupedTrails={groupedTrails}
containerPalette={containerPalette}
showAge={showAge}
hideAge={hideAge}
serverTime={serverTime}
imageLoading={imageLoading}
aspectRatio={aspectRatio}
Expand All @@ -80,7 +80,7 @@ export const DecideContainer = ({
<FlexibleGeneral
groupedTrails={groupedTrails}
containerPalette={containerPalette}
showAge={showAge}
hideAge={hideAge}
serverTime={serverTime}
imageLoading={imageLoading}
aspectRatio={aspectRatio}
Expand All @@ -98,7 +98,7 @@ export const DecideContainer = ({
trails={trails}
imageLoading={imageLoading}
containerPalette={containerPalette}
showAge={showAge}
hideAge={hideAge}
serverTime={serverTime}
aspectRatio={aspectRatio}
sectionId={sectionId}
Expand All @@ -112,7 +112,7 @@ export const DecideContainer = ({
trails={trails}
imageLoading={imageLoading}
containerPalette={containerPalette}
showAge={showAge}
hideAge={hideAge}
serverTime={serverTime}
aspectRatio={aspectRatio}
sectionId={sectionId}
Expand All @@ -127,7 +127,7 @@ export const DecideContainer = ({
<StaticMediumFour
trails={trails}
containerPalette={containerPalette}
showAge={showAge}
hideAge={hideAge}
serverTime={serverTime}
imageLoading={imageLoading}
aspectRatio={aspectRatio}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ export const FiveCardWithSingleBranding = () => {
trails={singleBrandedTrails}
speed="fast"
imageLoading="eager"
isTagPage={true}
aspectRatio={ASPECT_RATIO}
/>
</FrontSection>
Expand All @@ -325,7 +324,6 @@ export const FiveCardWithMultipleBranding = () => {
trails={multipleBrandedTrails}
speed="fast"
imageLoading="eager"
isTagPage={true}
aspectRatio={ASPECT_RATIO}
/>
</FrontSection>
Expand Down
Loading
Loading