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