2018-03-26 14:32:43 -07:00
|
|
|
// @flow
|
2019-11-29 16:21:32 -05:00
|
|
|
import type { Node } from 'react';
|
2017-12-21 18:08:54 -03:00
|
|
|
import React from 'react';
|
2020-01-21 17:38:10 -05:00
|
|
|
import classnames from 'classnames';
|
2018-03-26 14:32:43 -07:00
|
|
|
import Button from 'component/button';
|
2017-05-02 12:25:31 +07:00
|
|
|
|
2018-03-26 14:32:43 -07:00
|
|
|
type Props = {
|
|
|
|
isResolvingUri: boolean,
|
2019-04-24 10:02:08 -04:00
|
|
|
channelUri: ?string,
|
2018-05-07 00:50:55 -04:00
|
|
|
link: ?boolean,
|
2019-06-11 14:10:58 -04:00
|
|
|
claim: ?Claim,
|
2020-01-29 10:26:39 -05:00
|
|
|
hideAnonymous: boolean,
|
2018-05-07 00:50:55 -04:00
|
|
|
// 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?
|
2021-02-16 16:09:20 -05:00
|
|
|
resolveUri: (string) => void,
|
2018-03-26 14:32:43 -07:00
|
|
|
uri: string,
|
2019-11-29 16:21:32 -05:00
|
|
|
// to allow for other elements to be nested within the UriIndicator
|
|
|
|
children: ?Node,
|
2020-01-21 17:38:10 -05:00
|
|
|
inline: boolean,
|
2021-03-23 22:53:33 -04:00
|
|
|
external?: boolean,
|
2021-03-30 12:00:30 -04:00
|
|
|
className?: string,
|
2021-07-16 01:53:38 -05:00
|
|
|
focusable: boolean,
|
2018-03-26 14:32:43 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class UriIndicator extends React.PureComponent<Props> {
|
2019-06-11 14:10:58 -04:00
|
|
|
componentDidMount() {
|
2017-06-06 17:19:12 -04:00
|
|
|
this.resolve(this.props);
|
2017-05-21 10:42:34 -04:00
|
|
|
}
|
2017-05-02 12:25:31 +07:00
|
|
|
|
2019-06-11 14:10:58 -04:00
|
|
|
componentDidUpdate() {
|
|
|
|
this.resolve(this.props);
|
2017-05-09 23:06:48 -04:00
|
|
|
}
|
|
|
|
|
2018-03-26 14:32:43 -07:00
|
|
|
resolve = (props: Props) => {
|
2017-06-06 17:19:12 -04:00
|
|
|
const { isResolvingUri, resolveUri, claim, uri } = props;
|
2017-05-09 23:06:48 -04:00
|
|
|
|
2017-06-06 17:19:12 -04:00
|
|
|
if (!isResolvingUri && claim === undefined && uri) {
|
|
|
|
resolveUri(uri);
|
2017-05-21 10:42:34 -04:00
|
|
|
}
|
2018-03-26 14:32:43 -07:00
|
|
|
};
|
2017-05-02 12:25:31 +07:00
|
|
|
|
2017-05-21 10:42:34 -04:00
|
|
|
render() {
|
2021-03-30 12:00:30 -04:00
|
|
|
const {
|
|
|
|
link,
|
|
|
|
isResolvingUri,
|
|
|
|
claim,
|
|
|
|
children,
|
|
|
|
inline,
|
2021-07-16 01:53:38 -05:00
|
|
|
focusable = true,
|
2021-03-30 12:00:30 -04:00
|
|
|
external = false,
|
2021-07-16 01:53:38 -05:00
|
|
|
hideAnonymous = false,
|
2021-03-30 12:00:30 -04:00
|
|
|
className,
|
|
|
|
} = this.props;
|
2019-04-24 10:02:08 -04:00
|
|
|
|
2017-05-21 10:42:34 -04:00
|
|
|
if (!claim) {
|
2019-03-25 02:18:22 -04:00
|
|
|
return <span className="empty">{isResolvingUri ? 'Validating...' : 'Unused'}</span>;
|
2017-05-21 10:42:34 -04:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:10:58 -04:00
|
|
|
const isChannelClaim = claim.value_type === 'channel';
|
2021-09-10 14:27:21 -03:00
|
|
|
const signingChannel = claim.signing_channel && claim.signing_channel.amount;
|
|
|
|
if (!signingChannel && !isChannelClaim) {
|
2020-01-29 10:26:39 -05:00
|
|
|
if (hideAnonymous) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-01-25 13:34:21 -05:00
|
|
|
return (
|
2021-03-30 12:00:30 -04:00
|
|
|
<span dir="auto" className={classnames('channel-name', className, { 'channel-name--inline': inline })}>
|
2021-01-25 13:34:21 -05:00
|
|
|
Anonymous
|
|
|
|
</span>
|
|
|
|
);
|
2017-05-21 10:42:34 -04:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:10:58 -04:00
|
|
|
const channelClaim = isChannelClaim ? claim : claim.signing_channel;
|
2017-05-21 10:42:34 -04:00
|
|
|
|
2019-06-11 14:10:58 -04:00
|
|
|
if (channelClaim) {
|
2019-09-04 00:22:31 -04:00
|
|
|
const { name } = channelClaim;
|
2019-09-04 12:16:51 -04:00
|
|
|
const channelLink = link ? channelClaim.canonical_url || channelClaim.permanent_url : false;
|
2017-09-17 16:33:52 -04:00
|
|
|
|
2021-01-25 13:34:21 -05:00
|
|
|
const inner = (
|
|
|
|
<span dir="auto" className={classnames('channel-name', { 'channel-name--inline': inline })}>
|
|
|
|
{name}
|
|
|
|
</span>
|
|
|
|
);
|
2019-06-11 14:10:58 -04:00
|
|
|
|
|
|
|
if (!channelLink) {
|
|
|
|
return inner;
|
|
|
|
}
|
2017-09-17 16:33:52 -04:00
|
|
|
|
2019-12-03 20:30:29 -05:00
|
|
|
if (children) {
|
2021-03-23 22:53:33 -04:00
|
|
|
return (
|
2021-07-16 01:53:38 -05:00
|
|
|
<Button
|
|
|
|
aria-hidden={!focusable}
|
|
|
|
tabIndex={focusable ? 0 : -1}
|
|
|
|
className={className}
|
|
|
|
target={external ? '_blank' : undefined}
|
|
|
|
navigate={channelLink}
|
|
|
|
>
|
2021-03-23 22:53:33 -04:00
|
|
|
{children}
|
|
|
|
</Button>
|
|
|
|
);
|
2019-12-03 20:30:29 -05:00
|
|
|
} else {
|
|
|
|
return (
|
2021-03-30 12:00:30 -04:00
|
|
|
<Button
|
|
|
|
className={classnames(className, 'button--uri-indicator')}
|
|
|
|
navigate={channelLink}
|
|
|
|
target={external ? '_blank' : undefined}
|
2021-07-16 01:53:38 -05:00
|
|
|
aria-hidden={!focusable}
|
|
|
|
tabIndex={focusable ? 0 : -1}
|
2021-03-30 12:00:30 -04:00
|
|
|
>
|
2021-01-25 13:34:21 -05:00
|
|
|
{inner}
|
2019-12-03 20:30:29 -05:00
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
}
|
2019-06-11 14:10:58 -04:00
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
2017-05-21 10:42:34 -04:00
|
|
|
}
|
2017-05-02 12:25:31 +07:00
|
|
|
}
|
|
|
|
|
2017-06-05 21:21:55 -07:00
|
|
|
export default UriIndicator;
|