diff --git a/packages/shared/src/components/post/common/PostContentShare.tsx b/packages/shared/src/components/post/common/PostContentShare.tsx index 5a645fb2c7..fa3ab7f157 100644 --- a/packages/shared/src/components/post/common/PostContentShare.tsx +++ b/packages/shared/src/components/post/common/PostContentShare.tsx @@ -80,6 +80,8 @@ export function PostContentShare({ // shortens at press time and falls back to the tracked URL. link={post.commentsPermalink} onShare={onShare} + origin={Origin.PostContent} + post={post} text={post.title ?? post.sharedPost?.title ?? ''} title="Should anyone else see this post?" /> diff --git a/packages/shared/src/components/share/ShareActions.spec.tsx b/packages/shared/src/components/share/ShareActions.spec.tsx index 5a86a8de95..7136d56d56 100644 --- a/packages/shared/src/components/share/ShareActions.spec.tsx +++ b/packages/shared/src/components/share/ShareActions.spec.tsx @@ -12,6 +12,7 @@ import { ShareActions } from './ShareActions'; import { TestBootProvider } from '../../../__tests__/helpers/boot'; import { ShareProvider } from '../../lib/share'; import { useViewSize } from '../../hooks/useViewSize'; +import { postWithCommunitySentiment as sharedPost } from '../../../__tests__/fixture/post'; jest.mock('../../hooks/useViewSize', () => { const actual = jest.requireActual('../../hooks/useViewSize'); @@ -52,6 +53,15 @@ describe('ShareActions inline variant', () => { expect(screen.getByText('WhatsApp')).toBeInTheDocument(); }); + it('offers Slack only when there is a post to share', () => { + const { unmount } = renderComponent({ variant: 'inline' }); + expect(screen.queryByText('Slack')).not.toBeInTheDocument(); + unmount(); + + renderComponent({ variant: 'inline', post: sharedPost }); + expect(screen.getByText('Slack')).toBeInTheDocument(); + }); + it('copies the link and reports the CopyLink provider', async () => { renderComponent({ variant: 'inline' }); diff --git a/packages/shared/src/components/share/ShareActions.tsx b/packages/shared/src/components/share/ShareActions.tsx index a375ea9caf..555ef11e36 100644 --- a/packages/shared/src/components/share/ShareActions.tsx +++ b/packages/shared/src/components/share/ShareActions.tsx @@ -13,6 +13,8 @@ import { useShareOrCopyLink } from '../../hooks/useShareOrCopyLink'; import { shouldUseNativeShare } from '../../lib/func'; import { ShareProvider } from '../../lib/share'; import type { ReferralCampaignKey } from '../../lib/referral'; +import type { Post } from '../../graphql/posts'; +import type { Origin } from '../../lib/log'; import { CopyStateIcon } from './CopyStateIcon'; import { SplitShareButton } from './SplitShareButton'; @@ -23,6 +25,10 @@ export interface ShareActionsProps { /** Share text / description used for native share + pre-filled network text. */ text: string; cid?: ReferralCampaignKey; + /** The post being shared, when there is one: Slack shares a post. */ + post?: Post; + /** Where the Slack share starts, for its own events. */ + origin?: Origin; variant?: ShareActionsVariant; /** Desktop only: reveal the popover on hover as well as click. */ openOnHover?: boolean; @@ -50,6 +56,8 @@ export function ShareActions({ link, text, cid, + post, + origin, variant = 'icon', openOnHover = false, buttonVariant = ButtonVariant.Tertiary, @@ -87,6 +95,8 @@ export function ShareActions({