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';
|
|
|
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
// handle case of identifier and claim
|
|
|
|
if (identifier) {
|
|
|
|
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({
|
2018-01-31 02:15:23 +01:00
|
|
|
identifier: {
|
|
|
|
isChannel,
|
|
|
|
channelName,
|
|
|
|
channelClaimId,
|
|
|
|
claimId,
|
|
|
|
},
|
|
|
|
claim: {
|
|
|
|
claimName,
|
|
|
|
},
|
2018-01-30 18:00:02 +01:00
|
|
|
isServeRequest,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// handle case of just claim (asset or channel)
|
|
|
|
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;
|