From 27397285bc3a34d93f9f1d8676d7ccd44e888d0e Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Mon, 30 Mar 2020 15:43:27 -0400 Subject: [PATCH] use web share api --- ui/component/socialShare/index.js | 3 +- ui/component/socialShare/view.jsx | 192 ++++++++++++++++-------------- ui/scss/component/_modal.scss | 8 ++ ui/scss/component/_share.scss | 4 +- 4 files changed, 112 insertions(+), 95 deletions(-) diff --git a/ui/component/socialShare/index.js b/ui/component/socialShare/index.js index 6e87e2548..b91dcdd6c 100644 --- a/ui/component/socialShare/index.js +++ b/ui/component/socialShare/index.js @@ -1,5 +1,5 @@ import { connect } from 'react-redux'; -import { makeSelectClaimForUri } from 'lbry-redux'; +import { makeSelectClaimForUri, makeSelectTitleForUri } from 'lbry-redux'; import SocialShare from './view'; import { selectUserInviteReferralCode, selectUser } from 'lbryinc'; @@ -7,6 +7,7 @@ const select = (state, props) => ({ claim: makeSelectClaimForUri(props.uri)(state), referralCode: selectUserInviteReferralCode(state), user: selectUser(state), + title: makeSelectTitleForUri(props.uri)(state), }); export default connect(select)(SocialShare); diff --git a/ui/component/socialShare/view.jsx b/ui/component/socialShare/view.jsx index 88ce24946..c403abb5b 100644 --- a/ui/component/socialShare/view.jsx +++ b/ui/component/socialShare/view.jsx @@ -5,122 +5,130 @@ 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: Claim, + claim: StreamClaim, + title: ?string, webShareable: boolean, referralCode: string, user: any, }; -type State = { - showEmbed: boolean, - showExtra: boolean, -}; +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(); -class SocialShare extends React.PureComponent { - constructor(props: Props) { - super(props); - - this.state = { - showEmbed: false, - showExtra: false, - }; - this.input = undefined; + if (!claim) { + return null; } - input: ?HTMLInputElement; + 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)}`; - render() { - const { claim, referralCode, user, webShareable } = this.props; - const { showEmbed, showExtra } = this.state; - - if (!claim) { - return null; + function handleWebShareClick() { + if (navigator.share) { + navigator.share({ + title: title || claim.name, + url: window.location.href, + }); } - 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)}`; + } - return ( - - -
+ return ( + + +
+
- {showEmbed && } - {showExtra && ( -
- - -
+
+ + {SUPPORTS_SHARE_API && isMobile && ( +
+
+ )} + {showEmbed && } + {showExtra && ( +
+ + +
+ )} +
+ ); } export default SocialShare; diff --git a/ui/scss/component/_modal.scss b/ui/scss/component/_modal.scss index 92a675c1d..51295e915 100644 --- a/ui/scss/component/_modal.scss +++ b/ui/scss/component/_modal.scss @@ -1,3 +1,10 @@ +.ReactModal__Body--open { + #app { + height: 100vh; + overflow-y: hidden; + } +} + .modal-overlay { top: 0; left: 0; @@ -35,6 +42,7 @@ .card { box-shadow: none; + border: none; } .navigation { diff --git a/ui/scss/component/_share.scss b/ui/scss/component/_share.scss index f11da5a08..70b22dc78 100644 --- a/ui/scss/component/_share.scss +++ b/ui/scss/component/_share.scss @@ -1,8 +1,8 @@ .share { border-radius: 50%; .icon { - height: 2.5rem; - width: 2.5rem; + height: 2.2rem; + width: 2.2rem; stroke: none; }