// @flow import * as ICONS from 'constants/icons'; import React from 'react'; import Button from 'component/button'; import CopyableText from 'component/copyableText'; import EmbedTextArea from 'component/embedTextArea'; import { generateDownloadUrl } from 'util/lbrytv'; import useIsMobile from 'effects/use-is-mobile'; const IOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform); const SUPPORTS_SHARE_API = typeof navigator.share !== 'undefined'; type Props = { claim: StreamClaim, title: ?string, webShareable: boolean, referralCode: string, user: any, }; function SocialShare(props: Props) { const { claim, title, referralCode, user, webShareable } = props; const [showEmbed, setShowEmbed] = React.useState(false); const [showExtra, setShowExtra] = React.useState(false); const isMobile = useIsMobile(); if (!claim) { return null; } const { canonical_url: canonicalUrl, permanent_url: permanentUrl, name, claim_id: claimId } = claim; const isChannel = claim.value_type === 'channel'; const rewardsApproved = user && user.is_reward_approved; const OPEN_URL = 'https://open.lbry.com/'; const lbryUrl = canonicalUrl ? canonicalUrl.split('lbry://')[1] : permanentUrl.split('lbry://')[1]; const lbryWebUrl = lbryUrl.replace(/#/g, ':'); const encodedLbryURL: string = `${OPEN_URL}${encodeURIComponent(lbryWebUrl)}`; const referralParam: string = referralCode && rewardsApproved ? `?r=${referralCode}` : ''; const openDotLbryDotComUrl: string = `${OPEN_URL}${lbryWebUrl}${referralParam}`; const downloadUrl = `${generateDownloadUrl(name, claimId)}`; function handleWebShareClick() { if (navigator.share) { navigator.share({ title: title || claim.name, url: window.location.href, }); } } return (
{SUPPORTS_SHARE_API && isMobile && (
)} {showEmbed && } {showExtra && (
)}
); } export default SocialShare;