Skip to content

Commit

Permalink
Live blog block desktop sharebutton copy (#12872)
Browse files Browse the repository at this point in the history
* Use useMatchMedia to check width
  • Loading branch information
DanielCliftonGuardian authored Nov 27, 2024
1 parent 9bacc23 commit 3c10efb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 3 additions & 1 deletion dotcom-rendering/src/components/ArticleMeta.web.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { ArticleMeta, shouldShowContributor } from './ArticleMeta.web';
import { ConfigProvider } from './ConfigContext';

jest.mock('../lib/bridgetApi', () => jest.fn());

jest.mock('../lib/useMatchMedia', () => ({
useMatchMedia: jest.fn(() => true),
}));
describe('ArticleMeta', () => {
it('It should contain legacy class names to support customised styling in interactives', () => {
const format = {
Expand Down
15 changes: 12 additions & 3 deletions dotcom-rendering/src/components/ShareButton.importable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { css } from '@emotion/react';
import { palette, until } from '@guardian/source/foundations';
import { breakpoints, palette, until } from '@guardian/source/foundations';
import type { Size } from '@guardian/source/react-components';
import {
Button,
Expand All @@ -10,6 +10,7 @@ import {
import { useEffect, useMemo, useState } from 'react';
import { ArticleDesign, type ArticleFormat } from '../lib/articleFormat';
import { transparentColour } from '../lib/transparentColour';
import { useMatchMedia } from '../lib/useMatchMedia';
import { palette as themePalette } from '../palette';

type Props = {
Expand Down Expand Up @@ -189,6 +190,10 @@ export const ShareButton = ({
const isLiveBlogMeta =
format.design === ArticleDesign.LiveBlog && context === 'ArticleMeta';

const isDesktop = useMatchMedia(`(min-width: ${breakpoints.desktop}px)`);

const isLiveBlogBlockDesktop = isDesktop && context === 'LiveBlock';

const shareData = useMemo(
() => ({
title: webTitle,
Expand All @@ -202,14 +207,18 @@ export const ShareButton = ({
);

useEffect(() => {
if ('share' in navigator && navigator.canShare(shareData)) {
if (
!isLiveBlogBlockDesktop &&
'share' in navigator &&
navigator.canShare(shareData)
) {
setButtonKind('native');
} else if ('clipboard' in navigator) {
setButtonKind('copy');
} else {
setButtonKind('email');
}
}, [shareData]);
}, [shareData, isLiveBlogBlockDesktop]);

useEffect(() => {
if (!isCopied) return;
Expand Down

0 comments on commit 3c10efb

Please sign in to comment.