lbry-desktop/src/ui/component/uriIndicator/view.jsx

73 lines
1.8 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
import React from 'react';
2018-03-26 23:32:43 +02:00
import Button from 'component/button';
2018-04-18 06:03:01 +02:00
import { buildURI } from 'lbry-redux';
import type { Claim } from 'types/claim';
2017-05-02 07:25:31 +02:00
2018-03-26 23:32:43 +02:00
type Props = {
isResolvingUri: boolean,
claim: Claim,
link: ?boolean,
// Lint thinks we aren't using these, even though we are.
// Possibly because the resolve function is an arrow function that is passed in props?
2018-03-26 23:32:43 +02:00
resolveUri: string => void,
uri: string,
};
class UriIndicator extends React.PureComponent<Props> {
2017-05-21 16:42:34 +02:00
componentWillMount() {
2017-06-06 23:19:12 +02:00
this.resolve(this.props);
2017-05-21 16:42:34 +02:00
}
2017-05-02 07:25:31 +02:00
2018-03-26 23:32:43 +02:00
componentWillReceiveProps(nextProps: Props) {
2017-06-06 23:19:12 +02:00
this.resolve(nextProps);
2017-05-10 05:06:48 +02:00
}
2018-03-26 23:32:43 +02:00
resolve = (props: Props) => {
2017-06-06 23:19:12 +02:00
const { isResolvingUri, resolveUri, claim, uri } = props;
2017-05-10 05:06:48 +02:00
2017-06-06 23:19:12 +02:00
if (!isResolvingUri && claim === undefined && uri) {
resolveUri(uri);
2017-05-21 16:42:34 +02:00
}
2018-03-26 23:32:43 +02:00
};
2017-05-02 07:25:31 +02:00
2017-05-21 16:42:34 +02:00
render() {
2018-03-26 23:32:43 +02:00
const { claim, link, isResolvingUri } = this.props;
2017-05-21 16:42:34 +02:00
if (!claim) {
2019-03-18 06:09:50 +01:00
return <span className='empty'>{isResolvingUri ? 'Validating...' : 'Unused'}</span>;
2017-05-21 16:42:34 +02:00
}
2018-10-26 06:20:18 +02:00
const { channel_name: channelName, signature_is_valid: signatureIsValid, value } = claim;
2018-03-26 23:32:43 +02:00
2017-09-17 22:33:52 +02:00
const channelClaimId =
value && value.publisherSignature && value.publisherSignature.certificateId;
2017-05-21 16:42:34 +02:00
2018-10-26 06:20:18 +02:00
if (!channelName) {
2019-03-18 06:09:50 +01:00
return <span className='channel-name'>Anonymous</span>;
2017-05-21 16:42:34 +02:00
}
2018-03-26 23:32:43 +02:00
let channelLink;
2017-05-21 16:42:34 +02:00
if (signatureIsValid) {
2018-06-25 19:49:59 +02:00
channelLink = link ? buildURI({ channelName, claimId: channelClaimId }) : false;
2017-05-21 16:42:34 +02:00
}
2019-03-18 06:09:50 +01:00
const inner = <span className='channel-name'>{channelName}</span>;
2017-09-17 22:33:52 +02:00
if (!channelLink) {
return inner;
}
return (
2018-03-26 23:32:43 +02:00
<Button
noPadding
2019-03-18 06:09:50 +01:00
className='button--uri-indicator'
navigate='/show'
navigateParams={{ uri: channelLink, page: 1 }}
>
2017-09-17 22:33:52 +02:00
{inner}
2018-03-26 23:32:43 +02:00
</Button>
2017-09-17 22:33:52 +02:00
);
2017-05-21 16:42:34 +02:00
}
2017-05-02 07:25:31 +02:00
}
2017-06-06 06:21:55 +02:00
export default UriIndicator;