Skip to content

Commit

Permalink
ADSDEV-924 Add ads as children of LiveBlogPost article
Browse files Browse the repository at this point in the history
  • Loading branch information
alevito committed Oct 5, 2021
1 parent e1307c4 commit b11a15a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
7 changes: 5 additions & 2 deletions components/x-live-blog-post/src/LiveBlogPost.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const LiveBlogPost = (props) => {
standout = {},
articleUrl,
showShareButtons = false,
byline
byline,
ad
} = props

const showBreakingNewsLabel = standout.breakingNews || isBreakingNews
Expand All @@ -26,7 +27,8 @@ const LiveBlogPost = (props) => {
className={`live-blog-post ${styles['live-blog-post']}`}
data-trackable="live-post"
id={`post-${id || postId}`}
data-x-component="live-blog-post">
data-x-component="live-blog-post"
>
<div className="live-blog-post__meta">
<Timestamp publishedTimestamp={publishedDate || publishedTimestamp} />
</div>
Expand All @@ -38,6 +40,7 @@ const LiveBlogPost = (props) => {
dangerouslySetInnerHTML={{ __html: bodyHTML || content }}
/>
{showShareButtons && <ShareButtons postId={id || postId} articleUrl={articleUrl} title={title} />}
{ad}
</article>
)
}
Expand Down
12 changes: 10 additions & 2 deletions components/x-live-blog-wrapper/src/LiveBlogWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ const withLiveBlogWrapperActions = withActions({
}
})

const BaseLiveBlogWrapper = ({ posts = [], articleUrl, showShareButtons, id, liveBlogWrapperElementRef }) => {
const BaseLiveBlogWrapper = ({
posts = [],
ads = [],
articleUrl,
showShareButtons,
id,
liveBlogWrapperElementRef
}) => {
posts.sort((a, b) => {
const timestampA = a.publishedDate || a.publishedTimestamp
const timestampB = b.publishedDate || b.publishedTimestamp
Expand All @@ -37,12 +44,13 @@ const BaseLiveBlogWrapper = ({ posts = [], articleUrl, showShareButtons, id, liv
return 0
})

const postElements = posts.map((post) => (
const postElements = posts.map((post, index) => (
<LiveBlogPost
key={`live-blog-post-${post.id}`}
{...post}
articleUrl={articleUrl}
showShareButtons={showShareButtons}
ad={ads[index]}
/>
))

Expand Down
37 changes: 36 additions & 1 deletion components/x-live-blog-wrapper/storybook/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,37 @@ import React from 'react'
import { LiveBlogWrapper } from '../src/LiveBlogWrapper'
import '../../x-live-blog-post/dist/LiveBlogPost.css'

const Ad = (props) => {
const {
slotName,
targeting,
defaultFormat = 'false',
small = 'false',
medium = 'false',
large = 'false',
extra = 'false',
alignment = 'center'
} = props

const classes = `o-ads o-ads--${alignment} o-ads--transition`

return (
<div
data-o-ads-name={slotName}
data-o-ads-targeting={targeting}
data-o-ads-formats-default={defaultFormat}
data-o-ads-formats-small={small}
data-o-ads-formats-medium={medium}
data-o-ads-formats-large={large}
data-o-ads-formats-extra={extra}
data-o-ads-label="true"
aria-hidden="true"
tabIndex="-1"
className={classes}
/>
)
}

const defaultProps = {
message: 'Test',
posts: [
Expand Down Expand Up @@ -32,7 +63,11 @@ const defaultProps = {
articleUrl: 'https://www.ft.com/content/2b665ec7-a88f-3998-8f39-5371f9c791ed',
showShareButtons: true
}
]
],
ads: {
1: <Ad />,
2: <Ad />
}
}

export default {
Expand Down

0 comments on commit b11a15a

Please sign in to comment.