Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion dotcom-rendering/src/components/ArticleMeta.apps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type Props = {
isCommentable: boolean;
pageId?: string;
headline?: string;
isPreview?: boolean;
};

const metaGridContainer = css`
Expand Down Expand Up @@ -230,6 +231,7 @@ export const ArticleMetaApps = ({
isCommentable,
pageId,
headline,
isPreview,
}: Props) => {
const soleContributor = getSoleContributor(tags, byline);
const authorName = soleContributor?.title ?? 'Author Image';
Expand Down Expand Up @@ -373,7 +375,7 @@ export const ArticleMetaApps = ({
</div>
{shouldShowListenToArticleButton && (
<Island priority="feature" defer={{ until: 'visible' }}>
<ListenToArticle articleId={pageId} />
<ListenToArticle articleId={pageId} isPreview={isPreview} />
</Island>
)}
</div>
Expand Down
12 changes: 10 additions & 2 deletions dotcom-rendering/src/components/ListenToArticle.importable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { log } from '@guardian/libs';
import { useEffect, useState } from 'react';
import { getListenToArticleClient } from '../lib/bridgetApi';
import { useIsBridgetCompatible } from '../lib/useIsBridgetCompatible';
import { useConfig } from './ConfigContext';
import { ListenToArticleButton } from './ListenToArticleButton';

type Props = {
articleId: string;
isPreview?: boolean;
};

export const formatAudioDuration = (
Expand All @@ -24,12 +26,14 @@ export const formatAudioDuration = (
return formattedDuration;
};

export const ListenToArticle = ({ articleId }: Props) => {
export const ListenToArticle = ({ articleId, isPreview = false }: Props) => {
const { isDev } = useConfig();
const [showButton, setShowButton] = useState<boolean>(false);
const [audioDurationSeconds, setAudioDurationSeconds] = useState<
number | undefined
>(undefined);

console.log('ListenToArticle isPreview=', isPreview);
const isBridgetCompatible = useIsBridgetCompatible('8.7.0');
useEffect(() => {
if (isBridgetCompatible) {
Expand All @@ -55,8 +59,12 @@ export const ListenToArticle = ({ articleId }: Props) => {

setShowButton(false);
});
} else if (isPreview || isDev) {
// To facilitate design and development in non-Bridget compatible environments,
// we want to show the button if we're in preview mode or development mode
setShowButton(true);
}
}, [articleId, isBridgetCompatible]);
}, [articleId, isPreview, isDev, isBridgetCompatible]);

const listenToArticleHandler = () => {
void getListenToArticleClient()
Expand Down
4 changes: 3 additions & 1 deletion dotcom-rendering/src/layouts/CommentLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export const CommentLayout = (props: WebProps | AppsProps) => {
const isWeb = renderingTarget === 'Web';
const isApps = renderingTarget === 'Apps';
const {
config: { isPaidContent, host },
config: { isPaidContent, host, isPreview },
} = article;

const showBodyEndSlot =
Expand Down Expand Up @@ -460,6 +460,7 @@ export const CommentLayout = (props: WebProps | AppsProps) => {
>
<ListenToArticle
articleId={article.pageId}
isPreview={isPreview}
/>
</Island>
</div>
Expand Down Expand Up @@ -493,6 +494,7 @@ export const CommentLayout = (props: WebProps | AppsProps) => {
article.config.shortUrlId
}
pageId={article.config.pageId}
isPreview={isPreview}
></ArticleMetaApps>
</Hide>
<Hide when="below" breakpoint="leftCol">
Expand Down
4 changes: 3 additions & 1 deletion dotcom-rendering/src/layouts/ImmersiveLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export const ImmersiveLayout = (props: WebProps | AppProps) => {
const { article, format, renderingTarget, serverTime } = props;

const {
config: { isPaidContent, host, hasSurveyAd },
config: { isPaidContent, host, hasSurveyAd, isPreview },
editionId,
} = article;
const isWeb = renderingTarget === 'Web';
Expand Down Expand Up @@ -535,6 +535,7 @@ export const ImmersiveLayout = (props: WebProps | AppProps) => {
>
<ListenToArticle
articleId={article.pageId}
isPreview={isPreview}
/>
</Island>
</div>
Expand Down Expand Up @@ -588,6 +589,7 @@ export const ImmersiveLayout = (props: WebProps | AppProps) => {
article.config.shortUrlId
}
pageId={article.config.pageId}
isPreview={isPreview}
></ArticleMetaApps>
</Hide>
<Hide when="below" breakpoint="leftCol">
Expand Down
3 changes: 2 additions & 1 deletion dotcom-rendering/src/layouts/InteractiveLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ interface AppsProps extends CommonProps {
export const InteractiveLayout = (props: WebProps | AppsProps) => {
const { article, format, renderingTarget, serverTime } = props;
const {
config: { isPaidContent, host, hasSurveyAd },
config: { isPaidContent, host, hasSurveyAd, isPreview },
editionId,
} = article;

Expand Down Expand Up @@ -406,6 +406,7 @@ export const InteractiveLayout = (props: WebProps | AppsProps) => {
pageId={
article.config.pageId
}
isPreview={isPreview}
></ArticleMetaApps>
</Hide>
<Hide until="leftCol">
Expand Down
4 changes: 3 additions & 1 deletion dotcom-rendering/src/layouts/ShowcaseLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ interface AppsProps extends CommonProps {
export const ShowcaseLayout = (props: WebProps | AppsProps) => {
const { article, format, renderingTarget, serverTime } = props;
const {
config: { isPaidContent, host, hasSurveyAd },
config: { isPaidContent, host, hasSurveyAd, isPreview },
editionId,
} = article;
const isWeb = renderingTarget === 'Web';
Expand Down Expand Up @@ -427,6 +427,7 @@ export const ShowcaseLayout = (props: WebProps | AppsProps) => {
>
<ListenToArticle
articleId={article.pageId}
isPreview={isPreview}
/>
</Island>
</div>
Expand Down Expand Up @@ -468,6 +469,7 @@ export const ShowcaseLayout = (props: WebProps | AppsProps) => {
article.config.shortUrlId
}
pageId={article.config.pageId}
isPreview={isPreview}
></ArticleMetaApps>
</Hide>
<Hide until="leftCol">
Expand Down
4 changes: 3 additions & 1 deletion dotcom-rendering/src/layouts/StandardLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ interface AppProps extends Props {
export const StandardLayout = (props: WebProps | AppProps) => {
const { article, format, renderingTarget, serverTime } = props;
const {
config: { isPaidContent, host, hasSurveyAd },
config: { isPaidContent, host, hasSurveyAd, isPreview },
editionId,
} = article;

Expand Down Expand Up @@ -587,6 +587,7 @@ export const StandardLayout = (props: WebProps | AppProps) => {
article.config.shortUrlId
}
pageId={article.config.pageId}
isPreview={isPreview}
></ArticleMetaApps>
</div>
</Hide>
Expand Down Expand Up @@ -673,6 +674,7 @@ export const StandardLayout = (props: WebProps | AppProps) => {
>
<ListenToArticle
articleId={article.pageId}
isPreview={isPreview}
/>
</Island>
</div>
Expand Down
1 change: 1 addition & 0 deletions dotcom-rendering/src/server/render.article.apps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const renderArticle = (
darkModeAvailable: true,
assetOrigin: ASSET_ORIGIN,
editionId: frontendData.editionId,
isDev: process.env.NODE_ENV === 'development',
};

const { html, extractedCss } = renderToStringWithEmotion(
Expand Down
2 changes: 2 additions & 0 deletions dotcom-rendering/src/types/configContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ export type Config =
darkModeAvailable: boolean;
assetOrigin: AssetOrigin;
editionId: EditionId;
isDev?: boolean;
}>
| Readonly<{
renderingTarget: Extract<RenderingTarget, 'Apps'>;
darkModeAvailable: boolean;
assetOrigin: AssetOrigin;
editionId: EditionId;
isDev?: boolean;
}>;
Loading