({
post,
isBordered = false,
}: ShareBarProps)
| 37 | const maxVisibleSquadsWhenCollapsed = maxVisibleOptions - fixedOptions; |
| 38 | |
| 39 | export default function ShareBar({ |
| 40 | post, |
| 41 | isBordered = false, |
| 42 | }: ShareBarProps): ReactElement { |
| 43 | const [isExpanded, setIsExpanded] = useState(false); |
| 44 | const href = post.commentsPermalink; |
| 45 | const cid = ReferralCampaignKey.SharePost; |
| 46 | const { getShortUrl } = useGetShortUrl(); |
| 47 | const [copying, copyLink] = useCopyPostLink(); |
| 48 | const { logEvent } = useLogContext(); |
| 49 | const { openModal } = useLazyModal(); |
| 50 | const { logOpts } = useContext(ActiveFeedContext); |
| 51 | const { squads } = useAuthContext(); |
| 52 | |
| 53 | const shareableSquadsCount = useMemo( |
| 54 | () => getShareableSquads(squads).length, |
| 55 | [squads], |
| 56 | ); |
| 57 | const squadOptionsCount = shareableSquadsCount || 1; |
| 58 | const totalOptionsCount = fixedOptions + squadOptionsCount; |
| 59 | const shouldShowToggle = totalOptionsCount > maxVisibleOptions; |
| 60 | |
| 61 | const logShareEvent = (provider: ShareProvider) => |
| 62 | logEvent( |
| 63 | postLogEvent(LogEvent.SharePost, post, { |
| 64 | extra: { provider, origin: Origin.ShareBar }, |
| 65 | ...(logOpts && logOpts), |
| 66 | }), |
| 67 | ); |
| 68 | |
| 69 | const onClick = async (provider: ShareProvider) => { |
| 70 | logShareEvent(provider); |
| 71 | |
| 72 | const shortLink = await getShortUrl(href, cid); |
| 73 | const shareLink = getShareLink({ |
| 74 | provider, |
| 75 | link: shortLink, |
| 76 | text: post?.title || post?.sharedPost?.title, |
| 77 | }); |
| 78 | window.open(shareLink, '_blank'); |
| 79 | }; |
| 80 | |
| 81 | const logAndCopyLink = async () => { |
| 82 | const shortLink = await getShortUrl(href, cid); |
| 83 | copyLink({ link: shortLink }); |
| 84 | logShareEvent(ShareProvider.CopyLink); |
| 85 | }; |
| 86 | |
| 87 | const onShareToSquad = (squad: Squad) => { |
| 88 | logEvent(postLogEvent(LogEvent.StartShareToSquad, post)); |
| 89 | const postToShare = getPostToShare(post); |
| 90 | openModal({ |
| 91 | type: LazyModal.SmartComposer, |
| 92 | props: { |
| 93 | initialUrl: postToShare.permalink, |
| 94 | preview: postToShare, |
| 95 | initialSquadId: squad.id, |
| 96 | onPosted: () => logEvent(postLogEvent(LogEvent.ShareToSquad, post)), |
nothing calls this directly
no test coverage detected