split up url parsing functions
This commit is contained in:
parent
8fc44a4534
commit
aeaab8bf2d
4 changed files with 44 additions and 24 deletions
|
@ -1,6 +1,6 @@
|
|||
import React from 'react';
|
||||
import ShowLite from 'components/ShowLite';
|
||||
import ShowDetails from 'components/ShowDetails';
|
||||
import ShowLite from 'components/ShowAssetLite';
|
||||
import ShowDetails from 'components/ShowAssetDetails';
|
||||
import request from 'utils/request';
|
||||
|
||||
class ShowAsset extends React.Component {
|
||||
|
|
|
@ -3,6 +3,9 @@ import ShowAsset from 'components/ShowAsset';
|
|||
import ShowChannel from 'components/ShowChannel';
|
||||
import lbryUri from 'utils/lbryUri';
|
||||
|
||||
const CHANNEL = 'CHANNEL';
|
||||
const ASSET = 'ASSET';
|
||||
|
||||
class ShowPage extends React.Component {
|
||||
constructor (props) {
|
||||
super(props);
|
||||
|
@ -11,13 +14,27 @@ class ShowPage extends React.Component {
|
|||
claim : null,
|
||||
isServeRequest: null,
|
||||
};
|
||||
this.parseUrlAndUpdateState = this.parseUrlAndUpdateState.bind(this);
|
||||
this.parseAndUpdateIdentifierAndClaim = this.parseAndUpdateIdentifierAndClaim.bind(this);
|
||||
this.parseAndUpdateClaimOnly = this.parseAndUpdateClaimOnly.bind(this);
|
||||
}
|
||||
componentDidMount () {
|
||||
console.log('ShowPage did mount');
|
||||
this.parseUrlAndUpdateState();
|
||||
}
|
||||
parseUrlAndUpdateState () {
|
||||
const identifier = this.props.match.params.identifier;
|
||||
const claim = this.props.match.params.claim;
|
||||
// handle case of identifier and claim
|
||||
if (identifier) {
|
||||
return this.parseAndUpdateIdentifierAndClaim(identifier, claim);
|
||||
}
|
||||
this.parseAndUpdateClaimOnly(claim);
|
||||
}
|
||||
parseAndUpdateIdentifierAndClaim(identifier, claim) {
|
||||
// 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));
|
||||
|
@ -39,7 +56,10 @@ class ShowPage extends React.Component {
|
|||
isServeRequest,
|
||||
});
|
||||
}
|
||||
// handle case of just claim (asset or channel)
|
||||
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
|
||||
let isChannel, channelName, channelClaimId;
|
||||
try {
|
||||
({ isChannel, channelName, channelClaimId } = lbryUri.parseIdentifier(claim));
|
||||
|
|
Loading…
Reference in a new issue