Skip to content

Commit fe0e72c

Browse files
authored
Merge branch 'main' into skb/collapsable-banner-poc-3
2 parents 4a77541 + 3fbb586 commit fe0e72c

24 files changed

+280
-179
lines changed

dotcom-rendering/README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,17 @@ $ cd dotcom-rendering
3030

3131
### Install Node.js
3232

33-
To install and manage Node versions, we highly recommend installing a Node version manager such as [fnm](https://github.com/Schniz/fnm) (preferred), [nvm](https://github.com/nvm-sh/nvm) or [asdf](https://asdf-vm.com/guide/getting-started.html).
33+
We highly recommend installing a Node version manager such as [fnm](https://github.com/Schniz/fnm) (preferred), [nvm](https://github.com/nvm-sh/nvm) or [asdf](https://asdf-vm.com/guide/getting-started.html).
3434

35-
Ensure you're at the root directory of this project, then follow the instructions for your version manager to install Node.
35+
Install the Node version manager of your choice.
36+
37+
Ensure you're at the root directory of the project:
38+
39+
```
40+
cd ~/code/dotcom-rendering
41+
```
42+
43+
Run the command for your version manager to use the Node version as specified in [.nvmrc](../.nvmrc).
3644

3745
For `fnm` this will be:
3846

@@ -94,22 +102,20 @@ $ make install
94102

95103
If you get an Node version error then check the setup for your version manager.
96104

97-
### Running locally
105+
### Run
98106

99107
```sh
100108
$ make dev
101109
```
102110

103-
The development server will start on [http://localhost:3030](http://localhost:3030).
111+
The development server will start on [http://localhost:3030](http://localhost:3030)
104112

105-
A list of content types with example URLs are available on the [root path](http://localhost:3030).
113+
The development server home page lists examples of the various page and content types.
106114

107115
You can render a specific article by appending the production URL to the `Article` endpoint, for example:
108-
109116
http://localhost:3030/Article/https://www.theguardian.com/sport/2019/jul/28/tour-de-france-key-moments-egan-bernal-yellow-jersey
110117

111-
You can view the JSON representation of an article as sent to DCR by [Frontend](https://github.com/guardian/frontend), by appending `.json?dcr=true` to the production URL, for example:
112-
118+
You can view the JSON data model of a page as sent by [Frontend](https://github.com/guardian/frontend) to DCR by appending `.json?dcr=true` to the production URL, for example:
113119
https://www.theguardian.com/sport/2019/jul/28/tour-de-france-key-moments-egan-bernal-yellow-jersey.json?dcr=true
114120

115121
### Detailed setup

dotcom-rendering/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@emotion/server": "11.11.0",
2929
"@guardian/ab-core": "8.0.0",
3030
"@guardian/braze-components": "22.2.0",
31-
"@guardian/bridget": "8.5.1",
31+
"@guardian/bridget": "8.6.0",
3232
"@guardian/browserslist-config": "6.1.0",
3333
"@guardian/cdk": "61.4.0",
3434
"@guardian/commercial-core": "27.1.0",

dotcom-rendering/src/components/ArticleMeta.apps.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ export const ArticleMetaApps = ({
244244
const isAnalysis = format.design === ArticleDesign.Analysis;
245245
const isLiveBlog = format.design === ArticleDesign.LiveBlog;
246246
const isGallery = format.design === ArticleDesign.Gallery;
247+
const isVideo = format.design === ArticleDesign.Video;
247248

248249
const shouldShowFollowButtons = (layoutOrDesignType: boolean) =>
249250
layoutOrDesignType && !!byline && !isUndefined(soleContributor);
@@ -254,6 +255,9 @@ export const ArticleMetaApps = ({
254255
const isImmersiveOrAnalysisWithMultipleAuthors =
255256
(isAnalysis || isImmersive) && !!byline && isUndefined(soleContributor);
256257

258+
const shouldShowListenToArticleButton =
259+
!!pageId && !(isLiveBlog || isPicture || isGallery || isVideo);
260+
257261
return (
258262
<div
259263
className={
@@ -365,7 +369,7 @@ export const ArticleMetaApps = ({
365369
</MetaGridBranding>
366370
)}
367371
</div>
368-
{pageId !== undefined && (
372+
{shouldShowListenToArticleButton && (
369373
<Island priority="feature" defer={{ until: 'visible' }}>
370374
<ListenToArticle articleId={pageId} />
371375
</Island>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Meta, StoryObj } from '@storybook/react/*';
1+
import type { Meta, StoryObj } from '@storybook/react';
22
import { leftColumnDecorator } from '../../.storybook/decorators/gridDecorators';
33
import { defaultFormats } from '../../.storybook/decorators/splitThemeDecorator';
44
import { allModes } from '../../.storybook/modes';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Meta, StoryObj } from '@storybook/react/*';
1+
import type { Meta, StoryObj } from '@storybook/react';
22
import { allModes } from '../../.storybook/modes';
33
import { FootballTable as FootballTableComponent } from './FootballTable';
44

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Meta, StoryObj } from '@storybook/react/*';
1+
import type { Meta, StoryObj } from '@storybook/react';
22
import { FootballTable as TableDefault } from './FootballTable.stories';
33
import { FootballTableList as FootballTableListComponent } from './FootballTableList';
44

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Meta, StoryObj } from '@storybook/react/*';
1+
import type { Meta, StoryObj } from '@storybook/react';
22
import { regions } from '../../fixtures/manual/footballData';
33
import { WomensEuro2025 } from './FootballCompetitionNav.stories';
44
import { FootballTableList as TableListDefault } from './FootballTableList.stories';

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

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,53 @@ import { ListenToArticleButton } from './ListenToArticleButton';
77
type Props = {
88
articleId: string;
99
};
10+
11+
export const formatAudioDuration = (
12+
durationInSeconds: number,
13+
): string | undefined => {
14+
if (durationInSeconds >= 3600 || durationInSeconds <= 0) {
15+
return undefined;
16+
}
17+
const minutes = Math.floor((durationInSeconds % 3600) / 60);
18+
const seconds = durationInSeconds % 60;
19+
20+
const formattedDuration = `${minutes.toString()}:${seconds
21+
.toString()
22+
.padStart(2, '0')}`;
23+
24+
return formattedDuration;
25+
};
26+
1027
export const ListenToArticle = ({ articleId }: Props) => {
1128
const [showButton, setShowButton] = useState<boolean>(false);
29+
const [audioDurationSeconds, setAudioDurationSeconds] = useState<
30+
number | undefined
31+
>(undefined);
1232

13-
const isBridgetCompatible = useIsBridgetCompatible('8.5.1');
14-
33+
const isBridgetCompatible = useIsBridgetCompatible('8.6.0');
1534
useEffect(() => {
1635
if (isBridgetCompatible) {
1736
Promise.all([
1837
getListenToArticleClient().isAvailable(articleId),
1938
getListenToArticleClient().isPlaying(articleId),
39+
getListenToArticleClient().getAudioDurationSeconds(articleId),
2040
])
21-
.then(() =>
22-
// setShowButton(isAvailable && !isPlaying),
23-
setShowButton(false),
24-
)
41+
.then(() => {
42+
// TODO pending design implementation and AB test set up.
43+
// .then(({ isAvailable, isPlaying, audioDurationSeconds }) => {
44+
// setAudioDuration(
45+
// audioDurationSeconds ? audioDurationSeconds : undefined,
46+
// );
47+
// setShowButton(isAvailable && !isPlaying);
48+
setAudioDurationSeconds(undefined);
49+
setShowButton(false);
50+
})
2551
.catch((error) => {
2652
console.error(
2753
'Error fetching article audio status: ',
2854
error,
2955
);
56+
3057
setShowButton(false);
3158
});
3259
}
@@ -54,7 +81,14 @@ export const ListenToArticle = ({ articleId }: Props) => {
5481
};
5582
return (
5683
showButton && (
57-
<ListenToArticleButton onClickHandler={listenToArticleHandler} />
84+
<ListenToArticleButton
85+
onClickHandler={listenToArticleHandler}
86+
audioDuration={
87+
audioDurationSeconds !== undefined
88+
? formatAudioDuration(audioDurationSeconds)
89+
: undefined
90+
}
91+
/>
5892
)
5993
);
6094
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { formatAudioDuration } from './ListenToArticle.importable';
2+
3+
describe('format Audio Duration correctly', () => {
4+
const testCases = [
5+
{ input: -60, expected: undefined },
6+
{ input: 0, expected: undefined },
7+
{ input: 1, expected: '0:01' },
8+
{ input: 59, expected: '0:59' },
9+
{ input: 60, expected: '1:00' },
10+
{ input: 61, expected: '1:01' },
11+
{ input: 3599, expected: '59:59' },
12+
{ input: 3600, expected: undefined },
13+
];
14+
15+
for (const { input, expected } of testCases) {
16+
it(`correctly formats ${input} as ${expected}`, () => {
17+
expect(formatAudioDuration(input)).toEqual(expected);
18+
});
19+
}
20+
});

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@ export default meta;
1010

1111
type Story = StoryObj<typeof meta>;
1212

13-
export const ListenToArticleButton = {
13+
export const ListenToArticleWithDurationButton = {
1414
args: {
1515
onClickHandler: () => undefined,
16+
audioDuration: '3:02',
17+
},
18+
} satisfies Story;
19+
20+
export const ListenToArticleNoDurationButton = {
21+
args: {
22+
onClickHandler: () => undefined,
23+
audioDuration: undefined,
1624
},
1725
} satisfies Story;

0 commit comments

Comments
 (0)