lbry-desktop/ui/page/show/view.jsx

120 lines
3.9 KiB
React
Raw Normal View History

2018-03-26 14:32:43 -07:00
// @flow
2019-10-17 15:09:03 -04:00
import React, { useEffect } from 'react';
import { parseURI } from 'lbry-redux';
import { Redirect } from 'react-router';
2018-03-26 14:32:43 -07:00
import BusyIndicator from 'component/common/busy-indicator';
import ChannelPage from 'page/channel';
import FilePage from 'page/file';
2018-03-26 14:32:43 -07:00
import Page from 'component/page';
2018-04-24 14:17:11 -04:00
import Button from 'component/button';
import { SITE_TITLE } from 'config';
2018-03-26 14:32:43 -07:00
type Props = {
isResolvingUri: boolean,
resolveUri: string => void,
uri: string,
2019-04-24 10:02:08 -04:00
claim: StreamClaim,
2019-03-28 12:53:13 -04:00
location: UrlLocation,
2018-04-24 14:17:11 -04:00
blackListedOutpoints: Array<{
txid: string,
nout: number,
}>,
2019-10-17 15:09:03 -04:00
title: string,
2018-03-26 14:32:43 -07:00
};
2019-10-17 15:09:03 -04:00
function ShowPage(props: Props) {
const { isResolvingUri, resolveUri, uri, claim, blackListedOutpoints, location, title } = props;
const { channelName, channelClaimId, streamName, streamClaimId } = parseURI(uri);
const signingChannel = claim && claim.signing_channel;
2019-11-15 10:13:19 -05:00
const canonicalUrl = claim && claim.canonical_url;
2017-05-11 19:28:43 -04:00
2019-10-17 15:09:03 -04:00
useEffect(() => {
2019-10-13 13:19:39 -04:00
// @if TARGET='web'
2019-11-15 10:13:19 -05:00
if (canonicalUrl) {
const canonicalUrlPath = '/' + canonicalUrl.replace(/^lbry:\/\//, '').replace(/#/g, ':');
2019-10-13 13:19:39 -04:00
if (canonicalUrlPath !== window.location.pathname) {
history.replaceState(history.state, '', canonicalUrlPath);
}
}
// @endif
2019-11-15 10:13:19 -05:00
if (resolveUri && !isResolvingUri && uri && (claim === undefined || !canonicalUrl)) {
resolveUri(uri);
}
2019-11-15 10:13:19 -05:00
}, [resolveUri, isResolvingUri, canonicalUrl, uri]);
2019-10-17 15:09:03 -04:00
useEffect(() => {
if (title) {
document.title = title;
} else if (streamName) {
document.title = streamName;
} else if (channelName) {
document.title = channelName;
} else {
document.title = IS_WEB ? SITE_TITLE : 'LBRY';
2019-10-17 15:09:03 -04:00
}
return () => {
document.title = IS_WEB ? SITE_TITLE : 'LBRY';
2019-10-17 15:09:03 -04:00
};
}, [title, channelName, streamName]);
// @routinghax
if (channelName && !channelClaimId && streamName && !streamClaimId && !isResolvingUri && !claim) {
// Kinda hacky, but this is probably an old url
// Just redirect to the vanity channel
return <Redirect to={`/@${channelName}`} />;
2017-05-09 23:06:48 -04:00
}
2019-10-17 15:09:03 -04:00
let innerContent = '';
2019-10-17 15:09:03 -04:00
if (!claim || (claim && !claim.name)) {
if (claim && !claim.name) {
// While testing the normalization changes, Brannon found that `name` was missing sometimes
// This shouldn't happen, so hopefully this helps track it down
console.error('No name for associated claim: ', claim.claim_id); // eslint-disable-line no-console
}
2019-10-17 15:09:03 -04:00
innerContent = (
<Page>
{isResolvingUri && <BusyIndicator message={__('Loading decentralized data...')} />}
{!isResolvingUri && <span className="empty">{__("There's nothing available at this location.")}</span>}
</Page>
);
} else if (claim.name.length && claim.name[0] === '@') {
innerContent = <ChannelPage uri={uri} location={location} />;
} else if (claim && blackListedOutpoints) {
let isClaimBlackListed = false;
2019-10-17 15:09:03 -04:00
isClaimBlackListed = blackListedOutpoints.some(
outpoint =>
(signingChannel && outpoint.txid === signingChannel.txid && outpoint.nout === signingChannel.nout) ||
(outpoint.txid === claim.txid && outpoint.nout === claim.nout)
);
2019-03-04 11:57:07 -05:00
2019-10-17 15:09:03 -04:00
if (isClaimBlackListed) {
2017-06-06 17:19:12 -04:00
innerContent = (
2019-06-11 14:10:58 -04:00
<Page>
2019-10-17 15:09:03 -04:00
<section className="card card--section">
<div className="card__title">{uri}</div>
<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 className="card__actions">
<Button button="link" href="https://lbry.com/faq/dmca" label={__('Read More')} />
</div>
</section>
2018-03-26 14:32:43 -07:00
</Page>
2017-06-06 17:19:12 -04:00
);
2019-10-17 15:09:03 -04:00
} else {
innerContent = <FilePage uri={uri} location={location} />;
}
2017-05-09 23:06:48 -04:00
}
2019-10-17 15:09:03 -04:00
return innerContent;
}
2017-06-05 21:21:55 -07:00
export default ShowPage;