only percent-encodes share urls for twitter and facebook #2441
1 changed files with 30 additions and 25 deletions
|
@ -33,35 +33,40 @@ class SocialShare extends React.PureComponent<Props> {
|
||||||
const { speechShareable, onDone } = this.props;
|
const { speechShareable, onDone } = this.props;
|
||||||
const channelClaimId =
|
const channelClaimId =
|
||||||
value && value.publisherSignature && value.publisherSignature.certificateId;
|
value && value.publisherSignature && value.publisherSignature.certificateId;
|
||||||
const speechPrefix = 'https://spee.ch/';
|
|
||||||
const lbryPrefix = 'https://open.lbry.com/';
|
|
||||||
|
|
||||||
let speechURL;
|
const getSpeechUri = (): string => {
|
||||||
let lbryURL;
|
|
||||||
if (isChannel) {
|
if (isChannel) {
|
||||||
// For channel claims, the channel name (@something) is in `claim.name`
|
// For channel claims, the channel name (@something) is in `claim.name`
|
||||||
speechURL = `${claimName}:${claimId}`;
|
return `${claimName}:${claimId}`;
|
||||||
lbryURL = `${claimName}#${claimId}`;
|
|
||||||
} else {
|
} else {
|
||||||
// If it's for a regular claim, check if it has an associated channel
|
// If it's for a regular claim, check if it has an associated channel
|
||||||
speechURL =
|
return channelName && channelClaimId
|
||||||
channelName && channelClaimId
|
|
||||||
? `${channelName}:${channelClaimId}/${claimName}`
|
? `${channelName}:${channelClaimId}/${claimName}`
|
||||||
: `${claimId}/${claimName}`;
|
: `${claimId}/${claimName}`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
lbryURL =
|
const getLbryUri = (): string => {
|
||||||
channelName && channelClaimId
|
if (isChannel) {
|
||||||
|
// For channel claims, the channel name (@something) is in `claim.name`
|
||||||
|
return `${claimName}#${claimId}`;
|
||||||
|
} else {
|
||||||
|
// If it's for a regular claim, check if it has an associated channel
|
||||||
|
return channelName && channelClaimId
|
||||||
? `${channelName}#${channelClaimId}/${claimName}`
|
? `${channelName}#${channelClaimId}/${claimName}`
|
||||||
: `${claimName}#${claimId}`;
|
: `${claimName}#${claimId}`;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (lbryURL) {
|
const speechPrefix = 'https://spee.ch/';
|
||||||
lbryURL = `${lbryPrefix}${encodeURIComponent(lbryURL)}`;
|
const lbryPrefix = 'https://open.lbry.com/';
|
||||||
}
|
const lbryUri = getLbryUri();
|
||||||
|
const speechUri = getSpeechUri();
|
||||||
|
const encodedLbryURL: string = `${lbryPrefix}${encodeURIComponent(lbryUri)}`;
|
||||||
|
const lbryURL: string = `${lbryPrefix}${getLbryUri()}`;
|
||||||
|
|
||||||
if (speechURL) {
|
const encodedSpeechURL = `${speechPrefix}${encodeURIComponent(speechUri)}`;
|
||||||
speechURL = `${speechPrefix}${encodeURIComponent(speechURL)}`;
|
const speechURL = `${speechPrefix}${speechUri}`;
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
|
@ -76,7 +81,7 @@ class SocialShare extends React.PureComponent<Props> {
|
||||||
icon={ICONS.FACEBOOK}
|
icon={ICONS.FACEBOOK}
|
||||||
button="alt"
|
button="alt"
|
||||||
label={__('')}
|
label={__('')}
|
||||||
href={`https://facebook.com/sharer/sharer.php?u=${speechURL}`}
|
href={`https://facebook.com/sharer/sharer.php?u=${encodedSpeechURL}`}
|
||||||
/>
|
/>
|
||||||
</ToolTip>
|
</ToolTip>
|
||||||
<ToolTip onComponent body={__('Twitter')}>
|
<ToolTip onComponent body={__('Twitter')}>
|
||||||
|
@ -85,7 +90,7 @@ class SocialShare extends React.PureComponent<Props> {
|
||||||
icon={ICONS.TWITTER}
|
icon={ICONS.TWITTER}
|
||||||
button="alt"
|
button="alt"
|
||||||
label={__('')}
|
label={__('')}
|
||||||
href={`https://twitter.com/home?status=${speechURL}`}
|
href={`https://twitter.com/home?status=${encodedSpeechURL}`}
|
||||||
/>
|
/>
|
||||||
</ToolTip>
|
</ToolTip>
|
||||||
<ToolTip onComponent body={__('View on Spee.ch')}>
|
<ToolTip onComponent body={__('View on Spee.ch')}>
|
||||||
|
@ -110,7 +115,7 @@ class SocialShare extends React.PureComponent<Props> {
|
||||||
icon={ICONS.FACEBOOK}
|
icon={ICONS.FACEBOOK}
|
||||||
button="alt"
|
button="alt"
|
||||||
label={__('')}
|
label={__('')}
|
||||||
href={`https://facebook.com/sharer/sharer.php?u=${lbryURL}`}
|
href={`https://facebook.com/sharer/sharer.php?u=${encodedLbryURL}`}
|
||||||
/>
|
/>
|
||||||
</ToolTip>
|
</ToolTip>
|
||||||
<ToolTip onComponent body={__('Twitter')}>
|
<ToolTip onComponent body={__('Twitter')}>
|
||||||
|
@ -119,7 +124,7 @@ class SocialShare extends React.PureComponent<Props> {
|
||||||
icon={ICONS.TWITTER}
|
icon={ICONS.TWITTER}
|
||||||
button="alt"
|
button="alt"
|
||||||
label={__('')}
|
label={__('')}
|
||||||
href={`https://twitter.com/home?status=${lbryURL}`}
|
href={`https://twitter.com/home?status=${encodedLbryURL}`}
|
||||||
/>
|
/>
|
||||||
</ToolTip>
|
</ToolTip>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue