Skip to content

Commit

Permalink
Merge branch 'main' into cc/three-tier-banner-mobile-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
charleycampbell authored Dec 12, 2024
2 parents d04fd68 + c8f5b09 commit 6d1e3db
Show file tree
Hide file tree
Showing 14 changed files with 455 additions and 214 deletions.
203 changes: 203 additions & 0 deletions dotcom-rendering/src/components/BigSixOnwardsContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
import { css } from '@emotion/react';
import { from, headlineBold24, space } from '@guardian/source/foundations';
import { decideFormat } from '../lib/articleFormat';
import { useApi } from '../lib/useApi';
import { palette } from '../palette';
import type { DCRFrontCard } from '../types/front';
import type { FETrailType } from '../types/trails';
import { Card } from './Card/Card';
import { LI } from './Card/components/LI';
import { UL } from './Card/components/UL';
import { LeftColumn } from './LeftColumn';
import { Placeholder } from './Placeholder';

type OnwardsResponse = {
trails: FETrailType[];
heading: string;
displayname: string;
description: string;
};

const containerStyles = css`
display: flex;
flex-direction: column;
padding-bottom: ${space[6]}px;
${from.leftCol} {
flex-direction: row;
padding-right: 80px;
}
`;

const headerStyles = css`
${headlineBold24};
color: ${palette('--carousel-text')};
padding-bottom: ${space[2]}px;
padding-top: ${space[1]}px;
margin-left: 0;
`;
const mobileHeaderStyles = css`
${headerStyles};
${from.tablet} {
padding-left: 10px;
}
${from.leftCol} {
display: none;
}
`;

const convertFETrailToDcrTrail = (
trails: FETrailType[],
discussionApiUrl: string,
): DCRFrontCard[] =>
trails.map((trail) => ({
dataLinkName: 'onwards-content-card',
discussionId: trail.discussion?.discussionId,
discussionApiUrl,
format: decideFormat(trail.format),
headline: trail.headline,
image: {
src: trail.masterImage ?? '',
altText: trail.linkText ?? '',
},
isExternalLink: false,
onwardsSource: 'related-content',
showLivePlayable: false,
showQuotedHeadline: false,
url: trail.url,
webPublicationDate: trail.webPublicationDate,
}));

type Props = { url: string; discussionApiUrl: string };

/**
* Big Six refers to the style of the onwards content container. It displays six article
* cards in a gallery-style container, as opposed to a carousel.
*/
export const BigSixOnwardsContent = ({ url, discussionApiUrl }: Props) => {
const { data, error } = useApi<OnwardsResponse>(url);

if (error) {
// Send the error to Sentry and then prevent the element from rendering
window.guardian.modules.sentry.reportError(error, 'onwards-lower');
return null;
}

if (!data?.trails) {
return (
<Placeholder
height={580} // best guess at typical height
shouldShimmer={false}
backgroundColor={palette('--article-background')}
/>
);
}

const trails: DCRFrontCard[] = convertFETrailToDcrTrail(
data.trails,
discussionApiUrl,
);

const firstSlice75 = trails.slice(0, 1);
const firstSlice25 = trails.slice(1, 2);
const secondSlice25 = trails.slice(2, 6);

const heading = data.heading || data.displayname;

return (
<div
data-component="onwards-content-gallery-style"
css={containerStyles}
>
<LeftColumn>
<h2 css={headerStyles}>
<span>{heading}</span>
</h2>
</LeftColumn>
<h2 css={mobileHeaderStyles}>
<span>{heading}</span>
</h2>
<div>
<UL direction="row" padBottom={true}>
{firstSlice75.map((trail) => (
<LI key={trail.url} padSides={true} percentage="75%">
<Card
absoluteServerTimes={false}
imagePositionOnDesktop="right"
imagePositionOnMobile="top"
imageSize="large"
imageLoading="lazy"
linkTo={trail.url}
format={trail.format}
headlineText={trail.headline}
image={trail.image}
dataLinkName={`onwards-content-gallery-style ${trail.dataLinkName}`}
discussionId={trail.discussionId}
discussionApiUrl={trail.discussionApiUrl}
isExternalLink={trail.isExternalLink}
showAge={true}
webPublicationDate={trail.webPublicationDate}
onwardsSource="related-content"
/>
</LI>
))}
{firstSlice25.map((trail) => (
<LI
key={trail.url}
padSides={true}
showDivider={true}
percentage="25%"
>
<Card
absoluteServerTimes={false}
imagePositionOnDesktop="top"
imagePositionOnMobile="left"
imageSize="small"
imageLoading="lazy"
linkTo={trail.url}
format={trail.format}
headlineText={trail.headline}
image={trail.image}
dataLinkName={`onwards-content-gallery-style ${trail.dataLinkName}`}
discussionId={trail.discussionId}
discussionApiUrl={trail.discussionApiUrl}
isExternalLink={trail.isExternalLink}
showAge={true}
webPublicationDate={trail.webPublicationDate}
onwardsSource="related-content"
/>
</LI>
))}
</UL>
<UL direction="row">
{secondSlice25.map((trail, index) => (
<LI
key={trail.url}
padSides={true}
showDivider={index > 0}
>
<Card
absoluteServerTimes={false}
imagePositionOnDesktop="top"
imagePositionOnMobile="left"
imageSize="small"
imageLoading="lazy"
linkTo={trail.url}
format={trail.format}
headlineText={trail.headline}
image={trail.image}
dataLinkName={`onwards-content-gallery-style ${trail.dataLinkName}`}
discussionId={trail.discussionId}
discussionApiUrl={trail.discussionApiUrl}
isExternalLink={trail.isExternalLink}
showAge={true}
webPublicationDate={trail.webPublicationDate}
onwardsSource="related-content"
/>
</LI>
))}
</UL>
</div>
</div>
);
};
2 changes: 2 additions & 0 deletions dotcom-rendering/src/components/Carousel.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ const Title = ({
<span css={titleStyle(isCuratedContent)}>{title}</span>
</h2>
);

type CarouselCardProps = {
isFirst: boolean;
index: number;
Expand Down Expand Up @@ -500,6 +501,7 @@ const CarouselCard = ({
}: CarouselCardProps) => {
const isVideoContainer = containerType === 'fixed/video';
const cardImagePosition = isOnwardContent ? 'bottom' : 'top';

return (
<LI
percentage="25%"
Expand Down
25 changes: 21 additions & 4 deletions dotcom-rendering/src/components/FlexibleGeneral.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,15 @@ export const SplashCardLayout = ({
absoluteServerTimes,
imageLoading,
aspectRatio,
isLastRow,
}: {
cards: DCRFrontCard[];
imageLoading: Loading;
containerPalette?: DCRContainerPalette;
showAge?: boolean;
absoluteServerTimes: boolean;
aspectRatio: AspectRatio;
isLastRow: boolean;
}) => {
const card = cards[0];
if (!card) return null;
Expand All @@ -183,7 +185,11 @@ export const SplashCardLayout = ({
);

return (
<UL padBottom={true} hasLargeSpacing={true} showTopBar={false}>
<UL
padBottom={!isLastRow}
hasLargeSpacing={!isLastRow}
showTopBar={false}
>
<LI
padSides={true}
verticalDividerColour={palette('--card-border-supporting')}
Expand Down Expand Up @@ -268,6 +274,7 @@ export const BoostedCardLayout = ({
imageLoading,
aspectRatio,
isFirstRow,
isLastRow,
}: {
cards: DCRFrontCard[];
imageLoading: Loading;
Expand All @@ -276,6 +283,7 @@ export const BoostedCardLayout = ({
absoluteServerTimes: boolean;
aspectRatio: AspectRatio;
isFirstRow: boolean;
isLastRow: boolean;
}) => {
const card = cards[0];
if (!card) return null;
Expand All @@ -287,7 +295,11 @@ export const BoostedCardLayout = ({
liveUpdatesPosition,
} = decideCardProperties(card.boostLevel);
return (
<UL padBottom={true} hasLargeSpacing={true} showTopBar={!isFirstRow}>
<UL
showTopBar={!isFirstRow}
padBottom={!isLastRow}
hasLargeSpacing={!isLastRow}
>
<LI
padSides={true}
verticalDividerColour={palette('--card-border-supporting')}
Expand Down Expand Up @@ -333,6 +345,7 @@ export const StandardCardLayout = ({
isFirstRow,
isFirstStandardRow,
aspectRatio,
isLastRow,
}: {
cards: DCRFrontCard[];
imageLoading: Loading;
Expand All @@ -343,14 +356,15 @@ export const StandardCardLayout = ({
absoluteServerTimes: boolean;
showImage?: boolean;
aspectRatio: AspectRatio;
isLastRow: boolean;
}) => {
if (cards.length === 0) return null;

return (
<UL
direction="row"
padBottom={true}
hasLargeSpacing={true}
padBottom={!isLastRow}
hasLargeSpacing={!isLastRow}
showTopBar={!isFirstRow}
/** We use one full top bar for the first row and use a split one for subsequent rows */
splitTopBar={!isFirstStandardRow}
Expand Down Expand Up @@ -429,6 +443,7 @@ export const FlexibleGeneral = ({
absoluteServerTimes={absoluteServerTimes}
imageLoading={imageLoading}
aspectRatio={aspectRatio}
isLastRow={cards.length === 0}
/>
)}

Expand All @@ -444,6 +459,7 @@ export const FlexibleGeneral = ({
imageLoading={imageLoading}
aspectRatio={aspectRatio}
isFirstRow={!splash.length && i === 0}
isLastRow={i === groupedCards.length - 1}
/>
);

Expand All @@ -460,6 +476,7 @@ export const FlexibleGeneral = ({
isFirstRow={!splash.length && i === 0}
isFirstStandardRow={i === 0}
aspectRatio={aspectRatio}
isLastRow={i === groupedCards.length - 1}
/>
);
}
Expand Down
13 changes: 6 additions & 7 deletions dotcom-rendering/src/components/FlexibleSpecial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,15 @@ export const OneCardLayout = ({
absoluteServerTimes,
imageLoading,
aspectRatio,
isLastRow,
}: {
cards: DCRFrontCard[];
imageLoading: Loading;
containerPalette?: DCRContainerPalette;
showAge?: boolean;
absoluteServerTimes: boolean;
aspectRatio: AspectRatio;
isLastRow: boolean;
}) => {
const card = cards[0];
if (!card) return null;
Expand All @@ -137,7 +139,7 @@ export const OneCardLayout = ({
card.supportingContent?.length ?? 0,
);
return (
<UL padBottom={true} hasLargeSpacing={true}>
<UL padBottom={!isLastRow} hasLargeSpacing={!isLastRow}>
<LI padSides={true}>
<FrontCard
trail={card}
Expand Down Expand Up @@ -187,12 +189,7 @@ const TwoCardOrFourCardLayout = ({
if (cards.length === 0) return null;
const hasTwoOrFewerCards = cards.length <= 2;
return (
<UL
direction="row"
padBottom={true}
showTopBar={true}
hasLargeSpacing={true}
>
<UL direction="row" showTopBar={true}>
{cards.map((card, cardIndex) => {
return (
<LI
Expand Down Expand Up @@ -250,6 +247,7 @@ export const FlexibleSpecial = ({
absoluteServerTimes={absoluteServerTimes}
imageLoading={imageLoading}
aspectRatio={aspectRatio}
isLastRow={splash.length === 0 && cards.length === 0}
/>
<OneCardLayout
cards={splash}
Expand All @@ -258,6 +256,7 @@ export const FlexibleSpecial = ({
absoluteServerTimes={absoluteServerTimes}
imageLoading={imageLoading}
aspectRatio={aspectRatio}
isLastRow={cards.length === 0}
/>
<TwoCardOrFourCardLayout
cards={cards}
Expand Down
Loading

0 comments on commit 6d1e3db

Please sign in to comment.