lbry-desktop/src/renderer/component/socialShare/view.jsx

128 lines
4.1 KiB
React
Raw Normal View History

2018-09-12 18:42:15 +02:00
// @flow
import React from 'react';
import type { Claim } from 'types/claim';
import Button from 'component/button';
import * as icons from 'constants/icons';
2018-10-04 15:39:14 +02:00
import CopyableText from 'component/copyableText';
import ToolTip from 'component/common/tooltip';
2018-09-12 18:42:15 +02:00
type Props = {
claim: Claim,
onDone: () => void,
2018-10-04 15:39:14 +02:00
speechShareable: boolean,
2018-11-09 16:34:48 +01:00
isChannel: boolean,
2018-09-12 18:42:15 +02:00
};
class SocialShare extends React.PureComponent<Props> {
2018-11-09 16:34:48 +01:00
static defaultProps = {
isChannel: false,
};
2018-09-12 18:42:15 +02:00
constructor(props: Props) {
super(props);
this.input = undefined;
}
input: ?HTMLInputElement;
render() {
2018-11-09 16:34:48 +01:00
const { claim, isChannel } = this.props;
const { claim_id: claimId, name: claimName, channel_name: channelName, value } = claim;
2018-10-04 15:39:14 +02:00
const { speechShareable, onDone } = this.props;
const channelClaimId =
value && value.publisherSignature && value.publisherSignature.certificateId;
2018-10-06 00:19:31 +02:00
const speechPrefix = 'https://spee.ch/';
const lbryPrefix = 'https://open.lbry.io/';
2018-10-04 15:39:14 +02:00
2018-11-09 16:34:48 +01:00
let speechURL;
let lbryURL;
if (isChannel) {
// For channel claims, the channel name (@something) is in `claim.name`
speechURL = `${speechPrefix}${claimName}:${claimId}`;
lbryURL = `${lbryPrefix}${claimName}#${claimId}`;
} else {
// If it's for a regular claim, check if it has an associated channel
speechURL =
channelName && channelClaimId
? `${speechPrefix}${channelName}:${channelClaimId}/${claimName}`
: `${speechPrefix}${claimId}/${claimName}`;
2018-09-12 18:42:15 +02:00
2018-11-09 16:34:48 +01:00
lbryURL =
channelName && channelClaimId
? `${lbryPrefix}${channelName}#${channelClaimId}/${claimName}`
: `${lbryPrefix}${claimName}#${claimId}`;
}
2018-10-04 15:39:14 +02:00
2018-09-12 18:42:15 +02:00
return (
2018-09-26 19:48:07 +02:00
<section className="card__content">
2018-10-04 15:39:14 +02:00
{speechShareable && (
<div className="card__content">
<label className="card__subtitle">{__('Web link')}</label>
<CopyableText copyable={speechURL} noSnackbar />
2018-10-04 15:39:14 +02:00
<div className="card__actions card__actions--center">
<ToolTip onComponent body={__('Facebook')}>
<Button
iconColor="blue"
icon={icons.FACEBOOK}
button="alt"
label={__('')}
href={`https://facebook.com/sharer/sharer.php?u=${speechURL}`}
/>
</ToolTip>
<ToolTip onComponent body={__('Twitter')}>
<Button
iconColor="blue"
icon={icons.TWITTER}
button="alt"
label={__('')}
href={`https://twitter.com/home?status=${speechURL}`}
/>
</ToolTip>
<ToolTip onComponent body={__('View on Spee.ch')}>
<Button
icon={icons.GLOBE}
iconColor="blue"
button="alt"
label={__('')}
href={`${speechURL}`}
/>
</ToolTip>
</div>
</div>
)}
<div className="card__content">
<label className="card__subtitle">{__('LBRY App link')}</label>
<CopyableText copyable={lbryURL} noSnackbar />
<div className="card__actions card__actions--center">
<ToolTip onComponent body={__('Facebook')}>
<Button
iconColor="blue"
icon={icons.FACEBOOK}
button="alt"
label={__('')}
href={`https://facebook.com/sharer/sharer.php?u=${lbryURL}`}
/>
</ToolTip>
<ToolTip onComponent body={__('Twitter')}>
<Button
iconColor="blue"
icon={icons.TWITTER}
button="alt"
label={__('')}
href={`https://twitter.com/home?status=${lbryURL}`}
/>
</ToolTip>
</div>
2018-09-26 19:48:07 +02:00
</div>
<div className="card__actions">
<Button button="link" label={__('Done')} onClick={onDone} />
2018-09-12 18:42:15 +02:00
</div>
2018-09-26 19:48:07 +02:00
</section>
2018-09-12 18:42:15 +02:00
);
}
}
export default SocialShare;