fix channel links

This commit is contained in:
Sean Yesmunt 2018-11-09 10:34:48 -05:00
parent a48cbdeab7
commit 1c5e28653a
3 changed files with 39 additions and 17 deletions

View file

@ -10,9 +10,14 @@ type Props = {
claim: Claim, claim: Claim,
onDone: () => void, onDone: () => void,
speechShareable: boolean, speechShareable: boolean,
isChannel: boolean,
}; };
class SocialShare extends React.PureComponent<Props> { class SocialShare extends React.PureComponent<Props> {
static defaultProps = {
isChannel: false,
};
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
@ -22,27 +27,33 @@ class SocialShare extends React.PureComponent<Props> {
input: ?HTMLInputElement; input: ?HTMLInputElement;
render() { render() {
const { const { claim, isChannel } = this.props;
claim_id: claimId, const { claim_id: claimId, name: claimName, channel_name: channelName, value } = claim;
name: claimName,
channel_name: channelName,
value,
} = this.props.claim;
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 speechPrefix = 'https://spee.ch/';
const lbryPrefix = 'https://open.lbry.io/'; const lbryPrefix = 'https://open.lbry.io/';
const speechURL = 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 channelName && channelClaimId
? `${speechPrefix}${channelName}:${channelClaimId}/${claimName}` ? `${speechPrefix}${channelName}:${channelClaimId}/${claimName}`
: `${speechPrefix}${claimId}/${claimName}`; : `${speechPrefix}${claimId}/${claimName}`;
const lbryURL = lbryURL =
channelName && channelClaimId channelName && channelClaimId
? `${lbryPrefix}${channelName}#${channelClaimId}/${claimName}` ? `${lbryPrefix}${channelName}#${channelClaimId}/${claimName}`
: `${lbryPrefix}${claimName}#${claimId}`; : `${lbryPrefix}${claimName}#${claimId}`;
}
return ( return (
<section className="card__content"> <section className="card__content">

View file

@ -7,14 +7,20 @@ type Props = {
closeModal: () => void, closeModal: () => void,
uri: string, uri: string,
speechShareable: boolean, speechShareable: boolean,
isChannel: boolean,
}; };
class ModalSocialShare extends React.PureComponent<Props> { class ModalSocialShare extends React.PureComponent<Props> {
render() { render() {
const { closeModal, uri, speechShareable } = this.props; const { closeModal, uri, speechShareable, isChannel } = this.props;
return ( return (
<Modal isOpen onAborted={closeModal} type="custom" title={__('Share')}> <Modal isOpen onAborted={closeModal} type="custom" title={__('Share')}>
<SocialShare uri={uri} onDone={closeModal} speechShareable={speechShareable} /> <SocialShare
uri={uri}
onDone={closeModal}
speechShareable={speechShareable}
isChannel={isChannel}
/>
</Modal> </Modal>
); );
} }

View file

@ -103,7 +103,12 @@ class ChannelPage extends React.PureComponent<Props> {
button="alt" button="alt"
icon={icons.GLOBE} icon={icons.GLOBE}
label={__('Share Channel')} label={__('Share Channel')}
onClick={() => openModal({ id: MODALS.SOCIAL_SHARE }, { uri, speechShareable: true })} onClick={() =>
openModal(
{ id: MODALS.SOCIAL_SHARE },
{ uri, speechShareable: true, isChannel: true }
)
}
/> />
</div> </div>
<section className="card__content">{contentList}</section> <section className="card__content">{contentList}</section>