2018-01-30 18:00:02 +01:00
|
|
|
import React from 'react';
|
2018-02-01 04:12:54 +01:00
|
|
|
import ErrorPage from 'components/ErrorPage';
|
2018-02-02 04:36:08 +01:00
|
|
|
import ShowAsset from 'containers/ShowAsset';
|
2018-02-02 03:42:03 +01:00
|
|
|
import ShowChannel from 'containers/ShowChannel';
|
2018-01-30 18:00:02 +01:00
|
|
|
import lbryUri from 'utils/lbryUri';
|
|
|
|
|
|
|
|
class ShowPage extends React.Component {
|
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2018-02-01 23:29:33 +01:00
|
|
|
error: null,
|
2018-01-30 18:00:02 +01:00
|
|
|
};
|
2018-01-31 20:49:20 +01:00
|
|
|
this.parseUrlAndUpdateState = this.parseUrlAndUpdateState.bind(this);
|
|
|
|
this.parseAndUpdateIdentifierAndClaim = this.parseAndUpdateIdentifierAndClaim.bind(this);
|
|
|
|
this.parseAndUpdateClaimOnly = this.parseAndUpdateClaimOnly.bind(this);
|
2018-01-30 18:00:02 +01:00
|
|
|
}
|
|
|
|
componentDidMount () {
|
2018-01-31 02:15:23 +01:00
|
|
|
console.log('ShowPage did mount');
|
2018-01-30 18:00:02 +01:00
|
|
|
const identifier = this.props.match.params.identifier;
|
|
|
|
const claim = this.props.match.params.claim;
|
2018-01-31 23:50:35 +01:00
|
|
|
this.parseUrlAndUpdateState(identifier, claim);
|
|
|
|
}
|
|
|
|
componentWillReceiveProps (nextProps) {
|
|
|
|
if (this.props.match.params !== nextProps.match.params) {
|
|
|
|
console.log('received new params props');
|
|
|
|
const identifier = nextProps.match.params.identifier;
|
|
|
|
const claim = nextProps.match.params.claim;
|
|
|
|
this.parseUrlAndUpdateState(identifier, claim);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parseUrlAndUpdateState (identifier, claim) {
|
2018-01-30 18:00:02 +01:00
|
|
|
if (identifier) {
|
2018-01-31 20:49:20 +01:00
|
|
|
return this.parseAndUpdateIdentifierAndClaim(identifier, claim);
|
2018-01-30 18:00:02 +01:00
|
|
|
}
|
2018-01-31 20:49:20 +01:00
|
|
|
this.parseAndUpdateClaimOnly(claim);
|
|
|
|
}
|
2018-02-01 23:29:33 +01:00
|
|
|
parseAndUpdateIdentifierAndClaim (modifier, claim) {
|
2018-01-31 20:49:20 +01:00
|
|
|
// this is a request for an asset
|
|
|
|
// claim will be an asset claim
|
|
|
|
// the identifier could be a channel or a claim id
|
2018-02-01 23:29:33 +01:00
|
|
|
let isChannel, channelName, channelClaimId, claimId, claimName, extension;
|
2018-01-31 20:49:20 +01:00
|
|
|
try {
|
2018-02-01 23:29:33 +01:00
|
|
|
({ isChannel, channelName, channelClaimId, claimId } = lbryUri.parseIdentifier(modifier));
|
|
|
|
({ claimName, extension } = lbryUri.parseClaim(claim));
|
2018-01-31 20:49:20 +01:00
|
|
|
} catch (error) {
|
2018-02-01 04:12:54 +01:00
|
|
|
return this.setState({error: error.message});
|
2018-01-31 20:49:20 +01:00
|
|
|
}
|
2018-02-01 23:29:33 +01:00
|
|
|
// update the store
|
|
|
|
let requestedClaim = {
|
|
|
|
name : claimName,
|
|
|
|
modifier: {
|
|
|
|
id : null,
|
|
|
|
channel: null,
|
2018-01-31 20:49:20 +01:00
|
|
|
},
|
2018-02-01 23:29:33 +01:00
|
|
|
extension,
|
|
|
|
};
|
|
|
|
if (isChannel) {
|
|
|
|
requestedClaim['modifier']['channel'] = {
|
|
|
|
name: channelName,
|
|
|
|
id : channelClaimId,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
requestedClaim['modifier']['id'] = claimId;
|
|
|
|
}
|
|
|
|
return this.props.onClaimRequest(requestedClaim);
|
2018-01-31 20:49:20 +01:00
|
|
|
}
|
|
|
|
parseAndUpdateClaimOnly (claim) {
|
|
|
|
// this could be a request for an asset or a channel page
|
|
|
|
// claim could be an asset claim or a channel claim
|
2018-01-30 18:00:02 +01:00
|
|
|
let isChannel, channelName, channelClaimId;
|
|
|
|
try {
|
|
|
|
({ isChannel, channelName, channelClaimId } = lbryUri.parseIdentifier(claim));
|
|
|
|
} catch (error) {
|
2018-02-01 04:12:54 +01:00
|
|
|
return this.setState({error: error.message});
|
2018-01-30 18:00:02 +01:00
|
|
|
}
|
2018-02-01 23:29:33 +01:00
|
|
|
// return early if this request is for a channel
|
2018-01-30 18:00:02 +01:00
|
|
|
if (isChannel) {
|
2018-02-01 23:29:33 +01:00
|
|
|
const requestedChannel = {
|
|
|
|
name: channelName,
|
|
|
|
id : channelClaimId,
|
|
|
|
}
|
|
|
|
return this.props.onChannelRequest(requestedChannel);
|
2018-01-30 18:00:02 +01:00
|
|
|
}
|
2018-02-01 23:29:33 +01:00
|
|
|
// if not for a channel, parse the claim request
|
|
|
|
let claimName, extension; // if I am destructuring below, do I still need to declare these here?
|
2018-01-30 18:00:02 +01:00
|
|
|
try {
|
2018-02-01 23:29:33 +01:00
|
|
|
({claimName, extension} = lbryUri.parseClaim(claim));
|
2018-01-30 18:00:02 +01:00
|
|
|
} catch (error) {
|
2018-02-01 04:12:54 +01:00
|
|
|
return this.setState({error: error.message});
|
2018-01-30 18:00:02 +01:00
|
|
|
}
|
2018-02-01 23:29:33 +01:00
|
|
|
const requestedClaim = {
|
|
|
|
name : claimName,
|
|
|
|
modifier: null,
|
|
|
|
extension,
|
|
|
|
}
|
|
|
|
this.props.onClaimRequest(requestedClaim);
|
2018-01-30 18:00:02 +01:00
|
|
|
}
|
|
|
|
render () {
|
2018-01-31 02:15:23 +01:00
|
|
|
console.log('rendering ShowPage');
|
2018-02-01 04:12:54 +01:00
|
|
|
if (this.state.error) {
|
|
|
|
return (
|
|
|
|
<ErrorPage error={this.state.error}/>
|
|
|
|
);
|
|
|
|
}
|
2018-02-02 03:42:03 +01:00
|
|
|
if (this.props.request) {
|
|
|
|
if (this.props.request.channel) {
|
2018-01-31 02:15:23 +01:00
|
|
|
return (
|
2018-02-02 03:42:03 +01:00
|
|
|
<ShowChannel />
|
|
|
|
);
|
|
|
|
} else if (this.props.request.claim) {
|
|
|
|
return (
|
2018-02-02 04:36:08 +01:00
|
|
|
<ShowAsset />
|
2018-01-31 02:15:23 +01:00
|
|
|
);
|
|
|
|
}
|
2018-01-30 18:00:02 +01:00
|
|
|
}
|
|
|
|
return (
|
2018-02-02 03:42:03 +01:00
|
|
|
<p>loading...</p>
|
2018-01-30 18:00:02 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-02-01 23:29:33 +01:00
|
|
|
// props
|
|
|
|
// channel
|
|
|
|
// show
|
|
|
|
|
2018-01-30 18:00:02 +01:00
|
|
|
export default ShowPage;
|