2018-01-30 18:00:02 +01:00
|
|
|
import React from 'react';
|
2018-01-31 02:15:23 +01:00
|
|
|
import ShowAsset from 'components/ShowAsset';
|
2018-01-30 18:00:02 +01:00
|
|
|
import ShowChannel from 'components/ShowChannel';
|
|
|
|
import lbryUri from 'utils/lbryUri';
|
|
|
|
|
2018-01-31 20:49:20 +01:00
|
|
|
const CHANNEL = 'CHANNEL';
|
|
|
|
const ASSET = 'ASSET';
|
|
|
|
|
2018-01-30 18:00:02 +01:00
|
|
|
class ShowPage extends React.Component {
|
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2018-01-31 02:15:23 +01:00
|
|
|
identifier : null,
|
|
|
|
claim : null,
|
2018-01-30 18:00:02 +01:00
|
|
|
isServeRequest: null,
|
|
|
|
};
|
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-01-31 23:50:35 +01:00
|
|
|
parseAndUpdateIdentifierAndClaim (identifier, claim) {
|
2018-01-31 20:49:20 +01:00
|
|
|
// handle case of identifier and claim
|
|
|
|
// this is a request for an asset
|
|
|
|
// claim will be an asset claim
|
|
|
|
// the identifier could be a channel or a claim id
|
|
|
|
let isChannel, channelName, channelClaimId, claimId, claimName, isServeRequest;
|
|
|
|
try {
|
|
|
|
({ isChannel, channelName, channelClaimId, claimId } = lbryUri.parseIdentifier(identifier));
|
|
|
|
({ claimName, isServeRequest } = lbryUri.parseName(claim));
|
|
|
|
} catch (error) {
|
|
|
|
return console.log('error:', error);
|
|
|
|
}
|
|
|
|
// set state
|
|
|
|
return this.setState({
|
|
|
|
identifier: {
|
|
|
|
isChannel,
|
|
|
|
channelName,
|
|
|
|
channelClaimId,
|
|
|
|
claimId,
|
|
|
|
},
|
|
|
|
claim: {
|
|
|
|
claimName,
|
|
|
|
},
|
|
|
|
isServeRequest,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
parseAndUpdateClaimOnly (claim) {
|
|
|
|
// handle case of just 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-01-31 02:15:23 +01:00
|
|
|
return console.log('error:', error);
|
2018-01-30 18:00:02 +01:00
|
|
|
}
|
|
|
|
if (isChannel) {
|
|
|
|
return this.setState({
|
2018-01-31 02:15:23 +01:00
|
|
|
claim: {
|
|
|
|
isChannel,
|
|
|
|
channelName,
|
|
|
|
channelClaimId,
|
|
|
|
},
|
2018-01-30 18:00:02 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
let claimName, isServeRequest;
|
|
|
|
try {
|
|
|
|
({claimName, isServeRequest} = lbryUri.parseName(claim));
|
|
|
|
} catch (error) {
|
2018-01-31 02:15:23 +01:00
|
|
|
return console.log('error:', error);
|
2018-01-30 18:00:02 +01:00
|
|
|
}
|
|
|
|
this.setState({
|
2018-01-31 02:15:23 +01:00
|
|
|
claim: {
|
|
|
|
claimName,
|
|
|
|
},
|
2018-01-30 18:00:02 +01:00
|
|
|
isServeRequest,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
render () {
|
2018-01-31 02:15:23 +01:00
|
|
|
console.log('rendering ShowPage');
|
|
|
|
if (this.state.claim) {
|
|
|
|
if (this.state.claim.isChannel) {
|
|
|
|
return (
|
|
|
|
<ShowChannel
|
|
|
|
channelName={this.state.claim.channelName}
|
|
|
|
channelClaimId={this.state.claim.channelClaimId}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2018-01-30 18:00:02 +01:00
|
|
|
return (
|
2018-01-31 02:15:23 +01:00
|
|
|
<ShowAsset
|
|
|
|
identifier={this.state.identifier} // this.state.url.identifier
|
|
|
|
claim={this.state.claim} // this.state.url.claim
|
|
|
|
isServeRequest={this.state.isServeRequest} // this.state.url.ending
|
2018-01-30 18:00:02 +01:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return (
|
2018-01-31 02:15:23 +01:00
|
|
|
<p>Loading...</p>
|
2018-01-30 18:00:02 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ShowPage;
|