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