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