lbry-desktop/ui/component/socialShare/view.jsx

126 lines
3.9 KiB
React
Raw Normal View History

2018-09-12 18:42:15 +02:00
// @flow
2018-11-26 02:21:25 +01:00
import * as ICONS from 'constants/icons';
import React from 'react';
2018-09-12 18:42:15 +02:00
import Button from 'component/button';
2018-10-04 15:39:14 +02:00
import CopyableText from 'component/copyableText';
import EmbedTextArea from 'component/embedTextArea';
2020-03-27 19:57:03 +01:00
import { generateDirectUrl } from 'util/lbrytv';
const IOS = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);
2018-09-12 18:42:15 +02:00
type Props = {
2019-06-28 09:33:07 +02:00
claim: Claim,
2019-10-29 17:23:56 +01:00
webShareable: boolean,
2020-01-14 21:44:07 +01:00
referralCode: string,
user: any,
2018-09-12 18:42:15 +02:00
};
2020-03-27 19:57:03 +01:00
type State = {
showEmbed: boolean,
showExtra: boolean,
};
2018-11-09 16:34:48 +01:00
2020-03-27 19:57:03 +01:00
class SocialShare extends React.PureComponent<Props, State> {
2018-09-12 18:42:15 +02:00
constructor(props: Props) {
super(props);
2020-03-27 19:57:03 +01:00
this.state = {
showEmbed: false,
showExtra: false,
};
2018-09-12 18:42:15 +02:00
this.input = undefined;
}
input: ?HTMLInputElement;
render() {
2020-03-27 19:57:03 +01:00
const { claim, referralCode, user, webShareable } = this.props;
const { showEmbed, showExtra } = this.state;
if (!claim) {
return null;
}
const { canonical_url: canonicalUrl, permanent_url: permanentUrl, name, claim_id: claimId } = claim;
const isChannel = claim.value_type === 'channel';
2020-01-14 21:44:07 +01:00
const rewardsApproved = user && user.is_reward_approved;
2019-10-01 16:00:23 +02:00
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)}`;
2020-01-14 21:44:07 +01:00
const referralParam: string = referralCode && rewardsApproved ? `?r=${referralCode}` : '';
const lbryURL: string = `${OPEN_URL}${lbryWebUrl}${referralParam}`;
2020-03-27 19:57:03 +01:00
const directUrl = generateDirectUrl(name, claimId);
2018-10-04 15:39:14 +02:00
2018-09-12 18:42:15 +02:00
return (
<React.Fragment>
2020-03-27 19:57:03 +01:00
<CopyableText label={__('LBRY Link')} copyable={lbryURL} />
<div className="section__actions">
2019-07-21 23:31:22 +02:00
<Button
2020-03-27 19:57:03 +01:00
className="share"
iconSize={24}
2019-07-21 23:31:22 +02:00
icon={ICONS.TWITTER}
2019-07-23 22:16:37 +02:00
href={`https://twitter.com/intent/tweet?text=${encodedLbryURL}`}
2019-07-21 23:31:22 +02:00
/>
2020-03-27 19:57:03 +01:00
<Button
className="share"
iconSize={24}
icon={ICONS.REDDIT}
title={__('Share on Facebook')}
href={`https://reddit.com/submit?url=${encodedLbryURL}`}
/>
{IOS && (
// Only ios client supports share urls
<Button
className="share"
iconSize={24}
icon={ICONS.TELEGRAM}
title={__('Share on Telegram')}
href={`tg://msg_url?url=${encodedLbryURL}&amp;text=text`}
/>
)}
<Button
className="share"
iconSize={24}
icon={ICONS.LINKEDIN}
title={__('Share on LinkedIn')}
href={`https://www.linkedin.com/sharing/share-offsite/?url=${encodedLbryURL}`}
/>
<Button
className="share"
iconSize={24}
icon={ICONS.FACEBOOK}
title={__('Share on Facebook')}
href={`https://facebook.com/sharer/sharer.php?u=${encodedLbryURL}`}
/>
{webShareable && !isChannel && (
<React.Fragment>
<Button
className="share"
iconSize={24}
icon={ICONS.EMBED}
title={__('Embed this content')}
onClick={() => this.setState({ showEmbed: !showEmbed })}
/>
<Button
className="share"
iconSize={24}
icon={ICONS.MORE}
title={__('More actions')}
onClick={() => this.setState({ showExtra: !showExtra })}
/>
</React.Fragment>
)}
2018-09-26 19:48:07 +02:00
</div>
2020-03-27 19:57:03 +01:00
{showEmbed && <EmbedTextArea label={__('Embedded')} claim={claim} />}
{showExtra && (
<div className="section">
<CopyableText label={__('Direct Link')} copyable={directUrl} />
</div>
)}
</React.Fragment>
2018-09-12 18:42:15 +02:00
);
}
}
export default SocialShare;