Skip to content

Commit bb56ff7

Browse files
Football tables - pass the current date through components (#13674)
* Passes the server rendering iso time to the football match list component through the tree as it needs it to decide if it is going to render a link or not. Moves it from inside the component.
1 parent d9d338d commit bb56ff7

9 files changed

+19
-5
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type Story = StoryObj<typeof meta>;
3434

3535
export const Default = {
3636
args: {
37+
now: '2025-03-24T15:53:12.604Z',
3738
edition: 'UK',
3839
guardianBaseUrl: 'https://www.theguardian.com',
3940
initialDays,

dotcom-rendering/src/components/FootballMatchList.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Props = {
3232
edition: EditionId;
3333
guardianBaseUrl: string;
3434
getMoreDays?: () => Promise<Result<'failed', FootballMatches>>;
35+
now: string;
3536
};
3637

3738
const REMOVE_TRAILING_DOTS_REGEX = /\.+$/;
@@ -221,10 +222,12 @@ const MatchWrapper = ({
221222
children,
222223
}: {
223224
match: FootballMatch;
224-
now: Date;
225+
now: string;
225226
children: ReactNode;
226227
}) => {
227-
if (shouldRenderMatchLink(new Date(match.dateTimeISOString), now)) {
228+
if (
229+
shouldRenderMatchLink(new Date(match.dateTimeISOString), new Date(now))
230+
) {
228231
return (
229232
<li css={matchListItemStyles}>
230233
<a
@@ -260,7 +263,7 @@ const Match = ({
260263
}: {
261264
match: FootballMatch;
262265
timeFormatter: Intl.DateTimeFormat;
263-
now: Date;
266+
now: string;
264267
}) => (
265268
<MatchWrapper match={match} now={now}>
266269
<MatchStatus match={match} timeFormatter={timeFormatter} />
@@ -387,14 +390,13 @@ export const FootballMatchList = ({
387390
guardianBaseUrl,
388391
initialDays,
389392
getMoreDays,
393+
now,
390394
}: Props) => {
391395
const dateFormatter = getDateFormatter(edition);
392396
const timeFormatter = getTimeFormatter(edition);
393397

394398
const [days, setDays] = useState(initialDays);
395399
const [isError, setIsError] = useState<boolean>(false);
396-
const now = new Date();
397-
398400
return (
399401
<>
400402
{days.map((day) => (

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type Story = StoryObj<typeof meta>;
1313

1414
export const Results = {
1515
args: {
16+
now: '2025-03-24T15:53:12.604Z',
1617
regions,
1718
guardianBaseUrl: 'https://www.theguardian.com',
1819
kind: 'Result',

dotcom-rendering/src/components/FootballMatchesPage.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type Props = {
2828
getMoreDays?: () => Promise<Result<'failed', FootballMatches>>;
2929
renderAds: boolean;
3030
pageId: string;
31+
now: string;
3132
};
3233

3334
const createTitle = (kind: FootballMatchKind, edition: EditionId) => {
@@ -47,6 +48,7 @@ const createTitle = (kind: FootballMatchKind, edition: EditionId) => {
4748

4849
export const FootballMatchesPage = ({
4950
regions,
51+
now,
5052
guardianBaseUrl,
5153
kind,
5254
initialDays,
@@ -121,6 +123,7 @@ export const FootballMatchesPage = ({
121123
`}
122124
>
123125
<FootballMatchList
126+
now={now}
124127
initialDays={initialDays}
125128
edition={edition}
126129
getMoreDays={getMoreDays}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const goToCompetitionSpecificPage =
6363

6464
type Props = {
6565
regions: Region[];
66+
now: string;
6667
guardianBaseUrl: string;
6768
ajaxUrl: string;
6869
kind: FootballMatchKind;
@@ -75,6 +76,7 @@ type Props = {
7576

7677
export const FootballMatchesPageWrapper = ({
7778
regions,
79+
now,
7880
guardianBaseUrl,
7981
ajaxUrl,
8082
kind,
@@ -92,6 +94,7 @@ export const FootballMatchesPageWrapper = ({
9294
guardianBaseUrl={guardianBaseUrl}
9395
kind={kind}
9496
initialDays={initialDays}
97+
now={now}
9598
edition={edition}
9699
goToCompetitionSpecificPage={goToCompetitionSpecificPage(
97100
guardianBaseUrl,

dotcom-rendering/src/footballMatches.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ export type Region = {
379379

380380
export type DCRFootballDataPage = {
381381
matchesList: FootballMatches;
382+
now: string;
382383
kind: FootballMatchKind;
383384
nextPage?: string;
384385
previousPage?: string;

dotcom-rendering/src/layouts/FootballDataPageLayout.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Story = StoryObj<typeof meta>;
1515
export const Results = {
1616
args: {
1717
footballData: {
18+
now: '2025-03-24T15:53:12.604Z',
1819
matchesList: initialDays,
1920
regions,
2021
kind: 'Result',

dotcom-rendering/src/layouts/FootballDataPageLayout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export const FootballDataPageLayout = ({ footballData }: Props) => {
6363
<Island priority="feature" defer={{ until: 'visible' }}>
6464
<FootballMatchesPageWrapper
6565
regions={footballData.regions}
66+
now={footballData.now}
6667
guardianBaseUrl={footballData.guardianBaseURL}
6768
ajaxUrl={footballData.config.ajaxUrl}
6869
kind={footballData.kind}

dotcom-rendering/src/server/handler.footballDataPage.web.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const parseFEFootballData = (data: FEFootballDataPage): DCRFootballDataPage => {
7373

7474
return {
7575
matchesList: parsedMatchesList.value,
76+
now: new Date().toISOString(),
7677
kind: decidePageKind(data.config.pageId),
7778
nextPage: data.nextPage,
7879
previousPage: data.previousPage,

0 commit comments

Comments
 (0)