-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new layout for audio page (#12676)
Add a new layout file for the audio articles (podcasts) Moves Audio player up the grid --------- Co-authored-by: Alex Sanders <[email protected]>
- Loading branch information
1 parent
69fc256
commit 58998f6
Showing
10 changed files
with
976 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
dotcom-rendering/src/components/AudioPlayerWrapper.importable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { getConsentFor, onConsentChange } from '@guardian/libs'; | ||
import { useEffect, useState } from 'react'; | ||
import { AudioPlayer } from './AudioPlayer/AudioPlayer'; | ||
|
||
type Props = { | ||
mediaId: string; | ||
duration?: number; | ||
src: string; | ||
contentIsNotSensitive: boolean; | ||
isAcastEnabled: boolean; | ||
}; | ||
|
||
/** | ||
* ## Why does this need to be an Island? | ||
* | ||
* The audio player is interactive. | ||
* Requires consent to use audio ads. | ||
* | ||
* --- | ||
* | ||
* (No visual story exists) | ||
*/ | ||
export const AudioPlayerWrapper = ({ | ||
duration, | ||
src, | ||
mediaId, | ||
contentIsNotSensitive, | ||
isAcastEnabled, | ||
}: Props) => { | ||
const [finalSrc, setFinalSrc] = useState<string>(src); | ||
|
||
useEffect(() => { | ||
// this is how frontend checks for whether to show ads or not, | ||
// and it's on the window in DCR but it's not clear how... | ||
// so this just carries over the existing logic | ||
// https://github.com/guardian/frontend/blob/ba57677baaa06f37235e8d7a983cb383d0f5c989/static/src/javascripts/projects/common/modules/audio/index.js#L25-L44 | ||
const isPodcast = window.guardian.config.page.isPodcast; | ||
|
||
if (contentIsNotSensitive && isAcastEnabled && isPodcast) { | ||
onConsentChange((consentState) => { | ||
const consentForAcast = getConsentFor('acast', consentState); | ||
|
||
if (consentForAcast) { | ||
setFinalSrc( | ||
src.replace('https://', 'https://flex.acast.com/'), | ||
); | ||
} | ||
}); | ||
} | ||
}, [src, contentIsNotSensitive, isAcastEnabled]); | ||
|
||
return <AudioPlayer src={finalSrc} mediaId={mediaId} duration={duration} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { css } from '@emotion/react'; | ||
import { from } from '@guardian/source/foundations'; | ||
import type { ArticleFormat } from '../lib/articleFormat'; | ||
import type { TagType } from '../types/tag'; | ||
import { Picture } from './Picture'; | ||
|
||
const podcastResponsiveCoverImage = css` | ||
img { | ||
width: 140px; | ||
height: 140px; | ||
} | ||
margin-bottom: 0.375rem; | ||
${from.wide} { | ||
img { | ||
width: 219px; | ||
height: 219px; | ||
} | ||
} | ||
`; | ||
|
||
export const PodcastCoverImage = ({ | ||
format, | ||
series, | ||
}: { | ||
format: ArticleFormat; | ||
series: TagType; | ||
}) => { | ||
return ( | ||
<div css={podcastResponsiveCoverImage}> | ||
<Picture | ||
role={'podcastCover'} | ||
format={format} | ||
master={series.podcast?.image ?? ''} | ||
alt={series.title} | ||
height={1} | ||
width={1} | ||
loading="lazy" | ||
/> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,76 @@ | ||
import { css } from '@emotion/react'; | ||
import { palette } from '@guardian/source/foundations'; | ||
import { from, palette } from '@guardian/source/foundations'; | ||
import type { ArticleFormat } from '../lib/articleFormat'; | ||
import { ArticleDesign, ArticleDisplay, Pillar } from '../lib/articleFormat'; | ||
import type { TagType } from '../types/tag'; | ||
import { PodcastMeta } from './PodcastMeta'; | ||
|
||
const format: ArticleFormat = { | ||
design: ArticleDesign.Audio, | ||
display: ArticleDisplay.Standard, | ||
theme: Pillar.News, | ||
}; | ||
|
||
const podcastSeries: TagType = { | ||
id: 'lifeandstyle/series/comforteatingwithgracedent', | ||
type: 'Series', | ||
title: 'Comfort Eating with Grace Dent', | ||
podcast: { | ||
subscriptionUrl: | ||
'https://podcasts.apple.com/gb/podcast/comfort-eating-with-grace-dent/id1571446706', | ||
spotifyUrl: | ||
'https://open.spotify.com/show/5fMtMMKSlUoDuxhd3a3IS0?si=3B38GpeFThy4YtxSyNxApA&dl_branch=1', | ||
image: 'https://uploads.guim.co.uk/2023/09/18/GD_ComfortEating_3000x3000.jpg', | ||
}, | ||
}; | ||
|
||
const Wrapper = ({ children }: { children: React.ReactNode }) => ( | ||
<div | ||
css={css` | ||
width: 620px; | ||
padding: 20px; | ||
background-color: ${palette.neutral[7]}; | ||
margin: 20px; | ||
${from.leftCol} { | ||
width: 140px; | ||
} | ||
${from.wide} { | ||
width: 219px; | ||
} | ||
`} | ||
> | ||
{children} | ||
</div> | ||
); | ||
|
||
export const Default = () => ( | ||
<Wrapper> | ||
<PodcastMeta | ||
spotifyUrl="#" | ||
subscriptionUrl="#" | ||
rssFeedUrl="#" | ||
audioDownloadUrl="#" | ||
/> | ||
</Wrapper> | ||
<div | ||
css={css` | ||
width: 100%; | ||
height: 100%; | ||
background-color: ${palette.neutral[7]}; | ||
`} | ||
> | ||
<Wrapper> | ||
<PodcastMeta | ||
series={podcastSeries} | ||
format={format} | ||
spotifyUrl="#" | ||
subscriptionUrl="#" | ||
rssFeedUrl="#" | ||
audioDownloadUrl="#" | ||
/> | ||
</Wrapper> | ||
</div> | ||
); | ||
|
||
export default { | ||
component: PodcastMeta, | ||
title: 'Components/PodcastMeta', | ||
parameters: { | ||
formats: [ | ||
{ | ||
design: ArticleDesign.Audio, | ||
display: ArticleDisplay.Standard, | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.