lbry-desktop/src/renderer/page/show/view.jsx

99 lines
2.8 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
import React from 'react';
import { parseURI } from 'lbry-redux';
2018-03-26 23:32:43 +02:00
import BusyIndicator from 'component/common/busy-indicator';
import ChannelPage from 'page/channel';
import FilePage from 'page/file';
2018-03-26 23:32:43 +02:00
import Page from 'component/page';
2018-04-24 20:17:11 +02:00
import Button from 'component/button';
import type { Claim } from 'types/claim';
2018-03-26 23:32:43 +02:00
type Props = {
isResolvingUri: boolean,
resolveUri: string => void,
uri: string,
claim: Claim,
2018-04-24 20:17:11 +02:00
blackListedOutpoints: Array<{
txid: string,
nout: number,
}>,
2018-03-26 23:32:43 +02:00
};
class ShowPage extends React.PureComponent<Props> {
componentDidMount() {
const { isResolvingUri, resolveUri, uri } = this.props;
2017-05-12 01:28:43 +02:00
if (!isResolvingUri) resolveUri(uri);
2017-05-12 01:28:43 +02:00
}
2018-03-26 23:32:43 +02:00
componentWillReceiveProps(nextProps: Props) {
const { isResolvingUri, resolveUri, claim, uri } = nextProps;
2017-05-10 05:06:48 +02:00
if (!isResolvingUri && claim === undefined && uri) {
resolveUri(uri);
}
2017-05-10 05:06:48 +02:00
}
render() {
2018-04-24 20:17:11 +02:00
const { claim, isResolvingUri, uri, blackListedOutpoints } = this.props;
let innerContent = '';
if ((isResolvingUri && !claim) || !claim) {
const { claimName } = parseURI(uri);
2017-06-06 23:19:12 +02:00
innerContent = (
2018-03-26 23:32:43 +02:00
<Page>
<section className="card">
<h1>{claimName}</h1>
2018-03-26 23:32:43 +02:00
<div className="card__content">
{isResolvingUri && <BusyIndicator message={__('Loading decentralized data...')} />}
{claim === null &&
!isResolvingUri && (
<span className="empty">{__("There's nothing at this location.")}</span>
)}
2017-11-24 15:31:05 +01:00
</div>
2018-03-26 23:32:43 +02:00
</section>
</Page>
2017-06-06 23:19:12 +02:00
);
} else if (claim && claim.name.length && claim.name[0] === '@') {
2017-06-06 23:19:12 +02:00
innerContent = <ChannelPage uri={uri} />;
} else if (claim) {
2018-04-24 20:17:11 +02:00
let isClaimBlackListed = false;
for (let i = 0; i < blackListedOutpoints.length; i += 1) {
const outpoint = blackListedOutpoints[i];
if (outpoint.txid === claim.txid && outpoint.nout === claim.nout) {
isClaimBlackListed = true;
break;
}
}
if (isClaimBlackListed) {
innerContent = (
<Page>
<section className="card card--section">
<div className="card__title">{uri}</div>
<div className="card__content">
<p>
{__(
'In response to a complaint we received under the US Digital Millennium Copyright Act, we have blocked access to this content from our applications.'
)}
</p>
</div>
<div className="card__actions">
<Button button="link" href="https://lbry.io/faq/dmca" label={__('Read More')} />
</div>
</section>
</Page>
);
} else {
innerContent = <FilePage uri={uri} />;
}
}
2018-03-26 23:32:43 +02:00
return innerContent;
2017-05-10 05:06:48 +02:00
}
}
2017-06-06 06:21:55 +02:00
export default ShowPage;