sets <title> on show page

This commit is contained in:
jessop 2019-10-17 15:09:03 -04:00 committed by Sean Yesmunt
parent 37d4ea956b
commit b2079d561c
2 changed files with 75 additions and 62 deletions

View file

@ -5,6 +5,7 @@ import {
makeSelectClaimForUri,
makeSelectIsUriResolving,
makeSelectTotalPagesForChannel,
makeSelectTitleForUri,
normalizeURI,
} from 'lbry-redux';
import { selectBlackListedOutpoints } from 'lbryinc';
@ -36,6 +37,7 @@ const select = (state, props) => {
blackListedOutpoints: selectBlackListedOutpoints(state),
totalPages: makeSelectTotalPagesForChannel(uri, PAGE_SIZE)(state),
uri,
title: makeSelectTitleForUri(uri)(state),
};
};

View file

@ -1,5 +1,5 @@
// @flow
import React from 'react';
import React, { useEffect } from 'react';
import { parseURI } from 'lbry-redux';
import { Redirect } from 'react-router';
import BusyIndicator from 'component/common/busy-indicator';
@ -7,6 +7,7 @@ import ChannelPage from 'page/channel';
import FilePage from 'page/file';
import Page from 'component/page';
import Button from 'component/button';
import { DOMAIN } from 'config';
type Props = {
isResolvingUri: boolean,
@ -18,18 +19,19 @@ type Props = {
txid: string,
nout: number,
}>,
title: string,
};
class ShowPage extends React.PureComponent<Props> {
componentDidMount() {
const { isResolvingUri, resolveUri, uri } = this.props;
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;
if (!isResolvingUri) resolveUri(uri);
}
componentDidUpdate() {
const { isResolvingUri, resolveUri, claim, uri } = this.props;
useEffect(() => {
if (!isResolvingUri && resolveUri) resolveUri(uri);
}, [resolveUri]);
useEffect(() => {
// @if TARGET='web'
if (claim && claim.canonical_url) {
const canonicalUrlPath = '/' + claim.canonical_url.replace(/^lbry:\/\//, '').replace(/#/g, ':');
@ -38,73 +40,82 @@ class ShowPage extends React.PureComponent<Props> {
}
}
// @endif
if (!isResolvingUri && uri && claim === undefined) {
resolveUri(uri);
}
}
}, [resolveUri, isResolvingUri, claim, uri]);
render() {
const { claim, isResolvingUri, uri, blackListedOutpoints, location } = this.props;
const { channelName, channelClaimId, streamName, streamClaimId } = parseURI(uri);
const signingChannel = claim && claim.signing_channel;
// @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}`} />;
useEffect(() => {
if (title) {
document.title = title;
} else if (streamName) {
document.title = streamName;
} else if (channelName) {
document.title = channelName;
} else {
document.title = IS_WEB ? DOMAIN : 'LBRY';
}
let innerContent = '';
return () => {
document.title = IS_WEB ? DOMAIN : 'LBRY';
};
}, [title, channelName, streamName]);
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
}
// @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}`} />;
}
let innerContent = '';
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
}
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;
isClaimBlackListed = blackListedOutpoints.some(
outpoint =>
(signingChannel && outpoint.txid === signingChannel.txid && outpoint.nout === signingChannel.nout) ||
(outpoint.txid === claim.txid && outpoint.nout === claim.nout)
);
if (isClaimBlackListed) {
innerContent = (
<Page>
{isResolvingUri && <BusyIndicator message={__('Loading decentralized data...')} />}
{!isResolvingUri && <span className="empty">{__("There's nothing available at this location.")}</span>}
<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>
</Page>
);
} else if (claim.name.length && claim.name[0] === '@') {
innerContent = <ChannelPage uri={uri} location={location} />;
} else if (claim && blackListedOutpoints) {
let isClaimBlackListed = false;
isClaimBlackListed = blackListedOutpoints.some(
outpoint =>
(signingChannel && outpoint.txid === signingChannel.txid && outpoint.nout === signingChannel.nout) ||
(outpoint.txid === claim.txid && outpoint.nout === claim.nout)
);
if (isClaimBlackListed) {
innerContent = (
<Page>
<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>
</Page>
);
} else {
innerContent = <FilePage uri={uri} location={location} />;
}
} else {
innerContent = <FilePage uri={uri} location={location} />;
}
return innerContent;
}
return innerContent;
}
export default ShowPage;