2019-06-09 08:57:51 +02:00
|
|
|
// @flow
|
|
|
|
import * as React from 'react';
|
|
|
|
import { parseURI } from 'lbry-redux';
|
|
|
|
import Button from 'component/button';
|
2019-06-13 04:26:40 +02:00
|
|
|
|
|
|
|
import PreviewLink from 'component/previewLink';
|
2019-06-09 08:57:51 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uri: string,
|
|
|
|
title: ?string,
|
|
|
|
claim: StreamClaim,
|
|
|
|
children: React.Node,
|
|
|
|
thumbnail: ?string,
|
|
|
|
autoEmbed: ?boolean,
|
|
|
|
description: ?string,
|
|
|
|
isResolvingUri: boolean,
|
|
|
|
resolveUri: string => void,
|
|
|
|
blackListedOutpoints: Array<{
|
|
|
|
txid: string,
|
|
|
|
nout: number,
|
|
|
|
}>,
|
|
|
|
};
|
|
|
|
|
|
|
|
class ClaimLink extends React.Component<Props> {
|
|
|
|
static defaultProps = {
|
|
|
|
href: null,
|
|
|
|
title: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
isClaimBlackListed() {
|
|
|
|
const { claim, blackListedOutpoints } = this.props;
|
|
|
|
|
|
|
|
if (claim && blackListedOutpoints) {
|
|
|
|
let blackListed = false;
|
|
|
|
|
|
|
|
for (let i = 0; i < blackListedOutpoints.length; i += 1) {
|
|
|
|
const outpoint = blackListedOutpoints[i];
|
|
|
|
if (outpoint.txid === claim.txid && outpoint.nout === claim.nout) {
|
|
|
|
blackListed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return blackListed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
const { isResolvingUri, resolveUri, uri, claim } = this.props;
|
|
|
|
if (!isResolvingUri && !claim) {
|
|
|
|
resolveUri(uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate() {
|
|
|
|
const { isResolvingUri, resolveUri, claim, uri } = this.props;
|
|
|
|
if (!isResolvingUri && uri && !claim) {
|
|
|
|
resolveUri(uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-06-13 04:26:40 +02:00
|
|
|
const { uri, claim, title, autoEmbed, children, isResolvingUri } = this.props;
|
2019-06-09 08:57:51 +02:00
|
|
|
const { claimName } = parseURI(uri);
|
|
|
|
const blackListed = this.isClaimBlackListed();
|
2019-06-10 22:16:01 +02:00
|
|
|
const showPreview = autoEmbed === true && !blackListed && !isResolvingUri && claim !== null;
|
2019-06-09 08:57:51 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<React.Fragment>
|
2019-06-13 04:26:40 +02:00
|
|
|
<Button title={title || claimName} button={'link'} label={children} navigate={uri} />
|
|
|
|
{showPreview && <PreviewLink uri={uri} />}
|
2019-06-09 08:57:51 +02:00
|
|
|
</React.Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ClaimLink;
|