Skip to content

Commit 7d697ec

Browse files
committed
Implement FetchHostedOnwards component which is a client-side rendered component within an Island to render onward content for hosted content pages
1 parent 7984955 commit 7d697ec

4 files changed

Lines changed: 51 additions & 25 deletions

File tree

dotcom-rendering/src/components/FetchHostedOnwards.island.tsx

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,19 @@ type Props = {
99
};
1010

1111
type OnwardsResponse = {
12-
result: {
13-
owner: string;
14-
trails: Array<TrailType>;
15-
// trails: Array<{
16-
// /** URL of the article, used for the anchor tag */
17-
// url: string;
18-
// /** Headline of the article represented by trail */
19-
// headline: string;
20-
// /** Image thumbnail details for the article */
21-
// image: {
22-
// /** Trail image URL */
23-
// src: string;
24-
// /** Alt text for the trail image */
25-
// alt: string;
26-
// };
27-
// format: FEFormat;
28-
// }>;
29-
};
12+
trails: Array<TrailType>;
3013
};
3114

3215
export const FetchHostedOnwards = ({ branding, url }: Props) => {
33-
const { data } = useApi<OnwardsResponse>(url);
16+
const { data, error } = useApi<OnwardsResponse>(url);
3417

35-
const { result: { trails = [] } = {} } = data ?? {};
18+
if (error) {
19+
// Send the error to Sentry and then prevent the element from rendering
20+
window.guardian.modules.sentry.reportError(error, 'hosted-onwards');
21+
return null;
22+
}
23+
24+
const { trails = [] } = data ?? {};
3625

3726
if (!trails.length) {
3827
return null;

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,42 @@
1-
import { trails } from '../layouts/HostedArticleLayout';
1+
import type { TrailType } from '../types/trails';
22
import { HostedContentOnwards } from './HostedContentOnwards';
33

4+
const trails: TrailType[] = [
5+
{
6+
url: 'https://www.theguardian.com/money/gallery/2026/mar/27/loft-style-apartments-for-sale-in-england-in-pictures',
7+
headline: 'Loft-style apartments for sale in England – in pictures',
8+
format: { design: 27, display: 1, theme: 6 },
9+
dataLinkName: 'media | group-0 | card-@1',
10+
image: {
11+
src: 'https://media.guim.co.uk/276ed08e0380a9a3045a779ea1ca8c93f7c1b51e/500_0_5000_4000/2000.jpg',
12+
altText:
13+
'Loft-style apartment interior in Clapton, east London with industrial design elements',
14+
},
15+
},
16+
{
17+
url: 'https://www.theguardian.com/books/2026/apr/01/under-water-by-tara-menon-review-love-loss-and-a-longing-for-the-ocean',
18+
headline:
19+
'Under Water by Tara Menon review – love, loss and a longing for the ocean',
20+
format: { design: 27, display: 1, theme: 6 },
21+
dataLinkName: 'media | group-0 | card-@2',
22+
image: {
23+
src: 'https://media.guim.co.uk/95d6b3df9e3471344dc19a32d94bb3d5ff6f5016/205_5_2978_2382/2000.jpg',
24+
altText: 'Tropical fish',
25+
},
26+
},
27+
{
28+
url: 'https://www.theguardian.com/money/gallery/2026/feb/27/homes-a-short-walk-from-the-sea-in-england-and-scotland-in-pictures',
29+
headline:
30+
'Homes a short walk from the sea in England and Scotland – in pictures',
31+
format: { design: 27, display: 1, theme: 6 },
32+
dataLinkName: 'media | group-0 | card-@3',
33+
image: {
34+
src: 'https://media.guim.co.uk/9879e5d3275b5dae8c8bfd8e1ac700332e2de8c4/237_0_3750_3000/2000.jpg',
35+
altText: 'Craster, Northumberland',
36+
},
37+
},
38+
];
39+
440
export default {
541
component: HostedContentOnwards,
642
title: 'Components/HostedContentOnwards',

dotcom-rendering/src/layouts/HostedArticleLayout.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,7 @@ export const HostedArticleLayout = (props: WebProps | AppProps) => {
329329
<div css={onwardContentStyles}>
330330
<Island priority="feature" defer={{ until: 'idle' }}>
331331
<FetchHostedOnwards
332-
url={
333-
'http://localhost:9000/advertiser-content/we-are-still-in/faces-of-we-are-still-in/onward.json'
334-
}
332+
url={`${frontendData.config.ajaxUrl}/${frontendData.config.pageId}/onward.json`}
335333
branding={branding}
336334
/>
337335
</Island>

dotcom-rendering/src/layouts/HostedVideoLayout.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,10 @@ export const HostedVideoLayout = (props: WebProps | AppProps) => {
323323

324324
<div css={onwardContentStyles}>
325325
<Island priority="feature" defer={{ until: 'idle' }}>
326-
<FetchHostedOnwards branding={branding} />
326+
<FetchHostedOnwards
327+
url={`${frontendData.config.ajaxUrl}/${frontendData.config.pageId}/onward.json`}
328+
branding={branding}
329+
/>
327330
</Island>
328331
</div>
329332

0 commit comments

Comments
 (0)