// @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/web'; import { useIsMobile } from 'effects/use-screensize'; import { FormField } from 'component/common/form'; import { hmsToSeconds, secondsToHms } from 'util/time'; import { generateLbryContentUrl, generateLbryWebUrl, generateEncodedLbryURL, generateShareUrl } from 'util/url'; import { URL, SHARE_DOMAIN_URL } from 'config'; const SHARE_DOMAIN = SHARE_DOMAIN_URL || URL; 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, position: number, collectionId?: number, }; function SocialShare(props: Props) { const { claim, title, referralCode, user, webShareable, position, collectionId } = props; const [showEmbed, setShowEmbed] = React.useState(false); const [includeCollectionId, setIncludeCollectionId] = React.useState(Boolean(collectionId)); // unless it *is* a collection? const [showClaimLinks, setShowClaimLinks] = React.useState(false); const [includeStartTime, setincludeStartTime]: [boolean, any] = React.useState(false); const [startTime, setStartTime]: [string, any] = React.useState(secondsToHms(position)); const startTimeSeconds: number = hmsToSeconds(startTime); 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 isStream = claim.value_type === 'stream'; const isVideo = isStream && claim.value.stream_type === 'video'; const isAudio = isStream && claim.value.stream_type === 'audio'; const showStartAt = isVideo || isAudio; const rewardsApproved = user && user.is_reward_approved; const lbryUrl: string = generateLbryContentUrl(canonicalUrl, permanentUrl); const lbryWebUrl: string = generateLbryWebUrl(lbryUrl); const includedCollectionId = collectionId && includeCollectionId ? collectionId : null; const encodedLbryURL: string = generateEncodedLbryURL( SHARE_DOMAIN, lbryWebUrl, includeStartTime, startTimeSeconds, includedCollectionId ); const shareUrl: string = generateShareUrl( SHARE_DOMAIN, lbryUrl, referralCode, rewardsApproved, includeStartTime, startTimeSeconds, includedCollectionId ); const downloadUrl = `${generateDownloadUrl(name, claimId)}`; function handleWebShareClick() { if (navigator.share) { navigator.share({ title: title || claim.name, url: window.location.href, }); } } return ( {showStartAt && (
setincludeStartTime(!includeStartTime)} checked={includeStartTime} label={__('Start at')} /> setStartTime(event.target.value)} />
)} {Boolean(collectionId) && (
setIncludeCollectionId(!includeCollectionId)} checked={includeCollectionId} label={__('Include List ID')} />
)}
{SUPPORTS_SHARE_API && isMobile && (
)} {showEmbed && ( )} {showClaimLinks && (
{Boolean(isStream) && }
)}
); } export default SocialShare;