fix infinite resolve, add valid uri check

This commit is contained in:
Jeremy Kauffman 2017-05-12 16:49:15 -04:00
parent 950f3183cf
commit c823ccd056
4 changed files with 31 additions and 7 deletions

View file

@ -86,6 +86,7 @@ class FileTile extends React.Component {
const uri = lbryuri.normalize(this.props.uri);
const isClaimed = !!claim;
const isClaimable = lbryuri.isClaimable(uri)
const title = isClaimed && metadata && metadata.title ? metadata.title : uri;
const obscureNsfw = this.props.obscureNsfw && metadata && metadata.nsfw;
let onClick = () => navigate('/show', { uri })
@ -97,7 +98,10 @@ class FileTile extends React.Component {
description = "Loading..."
} else if (showEmpty === FileTile.SHOW_EMPTY_PUBLISH) {
onClick = () => navigate('/publish')
description = <span className="empty">This location is unclaimed - <span className="button-text">put something here</span>!</span>
description = <span className="empty">
This location is unused. { ' ' }
{ isClaimable && <span className="button-text">Put something here!</span> }
</span>
} else if (showEmpty === FileTile.SHOW_EMPTY_PENDING) {
description = <span className="empty">This file is pending confirmation.</span>
}

View file

@ -165,5 +165,25 @@ lbryuri.normalize= function(uri) {
return lbryuri.build({name, path, claimSequence, bidPosition, claimId});
}
lbryuri.isValid = function(uri) {
let parts
try {
parts = lbryuri.parse(lbryuri.normalize(uri))
} catch (error) {
return false;
}
return parts && parts.name;
}
lbryuri.isClaimable = function(uri) {
let parts
try {
parts = lbryuri.parse(lbryuri.normalize(uri))
} catch (error) {
return false;
}
return parts && parts.name && !parts.claimId && !parts.bidPosition && !parts.claimSequence && !parts.isChannel && !parts.path;
}
window.lbryuri = lbryuri;
export default lbryuri;

View file

@ -8,14 +8,13 @@ import {BusyMessage} from 'component/common.js';
class SearchPage extends React.Component{
render() {
const isValidUri = (query) => true //FIXME
const {
query,
} = this.props
return (
<main className="main--single-column">
{ isValidUri(query) ?
{ lbryuri.isValid(query) ?
<section className="section-spaced">
<h3 className="card-row__header">
Exact URL <ToolTip label="?" body="This is the resolution of a LBRY URL and not controlled by LBRY Inc."

View file

@ -21,7 +21,7 @@ class ShowPage extends React.Component{
uri,
} = props
if(!isResolvingUri && !claim && uri) {
if(!isResolvingUri && claim === undefined && uri) {
resolveUri(uri)
}
}
@ -35,15 +35,16 @@ class ShowPage extends React.Component{
let innerContent = "";
if (isResolvingUri) {
if (isResolvingUri || claim === null) {
innerContent = <section className="card">
<div className="card__inner">
<div className="card__title-identity"><h1>{uri}</h1></div>
</div>
<div className="card__content">
<BusyMessage message="Loading magic decentralized data..." />
{ isResolvingUri && <BusyMessage message="Loading magic decentralized data..." /> }
{ claim === null && <span className="empty">There's nothing at this location.</span> }
</div>
</section>;
</section>
}
else if (claim && claim.whatever) {
innerContent = "channel"