updated show asset components to use redux state
This commit is contained in:
parent
a00ff9203c
commit
b7ca5ac1ac
7 changed files with 51 additions and 38 deletions
|
@ -35,8 +35,9 @@ export function updateChannelClaimsData (claims, currentPage, totalPages, totalC
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function updateClaimData (claimData) {
|
export function updateClaimData (data) {
|
||||||
return {
|
return {
|
||||||
type: actions.CHANNEL_DATA_UPDATE,
|
type: actions.CLAIM_DATA_UPDATE,
|
||||||
|
data,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,7 +27,7 @@ class ShowDetails extends React.Component {
|
||||||
<AssetDisplay
|
<AssetDisplay
|
||||||
name={this.props.claimData.name}
|
name={this.props.claimData.name}
|
||||||
claimId={this.props.claimData.claimId}
|
claimId={this.props.claimData.claimId}
|
||||||
src={`/${this.props.claimId}/${this.props.name}.${this.props.fileExt}`}
|
src={`/${this.props.claimData.claimId}/${this.props.claimData.name}.${this.props.claimData.fileExt}`}
|
||||||
contentType={this.props.claimData.contentType}
|
contentType={this.props.claimData.contentType}
|
||||||
fileExt={this.props.claimData.fileExt}
|
fileExt={this.props.claimData.fileExt}
|
||||||
thumbnail={this.props.claimData.thumbnail}
|
thumbnail={this.props.claimData.thumbnail}
|
||||||
|
|
|
@ -14,7 +14,7 @@ class ShowLite extends React.Component {
|
||||||
<AssetDisplay
|
<AssetDisplay
|
||||||
name={this.props.claimData.name}
|
name={this.props.claimData.name}
|
||||||
claimId={this.props.claimData.claimId}
|
claimId={this.props.claimData.claimId}
|
||||||
src={`/${this.props.claimId}/${this.props.name}.${this.props.fileExt}`}
|
src={`/${this.props.claimData.claimId}/${this.props.claimData.name}.${this.props.claimData.fileExt}`}
|
||||||
contentType={this.props.claimData.contentType}
|
contentType={this.props.claimData.contentType}
|
||||||
fileExt={this.props.claimData.fileExt}
|
fileExt={this.props.claimData.fileExt}
|
||||||
thumbnail={this.props.claimData.thumbnail}
|
thumbnail={this.props.claimData.thumbnail}
|
||||||
|
|
24
react/containers/ShowAsset/index.js
Normal file
24
react/containers/ShowAsset/index.js
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
import { updateClaimData } from 'actions/show';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import View from './view';
|
||||||
|
|
||||||
|
const mapStateToProps = ({ show }) => {
|
||||||
|
return {
|
||||||
|
request: {
|
||||||
|
modifier : show.request.claim.modifier,
|
||||||
|
claim : show.request.claim.name,
|
||||||
|
extension: show.request.claim.extension,
|
||||||
|
},
|
||||||
|
claim: show.claim,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const mapDispatchToProps = dispatch => {
|
||||||
|
return {
|
||||||
|
onClaimDataChange: (data) => {
|
||||||
|
dispatch(updateClaimData(data));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default connect(mapStateToProps, mapDispatchToProps)(View);
|
|
@ -1,14 +1,13 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ShowAssetLite from 'components/ShowAssetLite';
|
import ShowAssetLite from 'components/ShowAssetLite/index';
|
||||||
import ShowAssetDetails from 'components/ShowAssetDetails';
|
import ShowAssetDetails from 'components/ShowAssetDetails/index';
|
||||||
import request from 'utils/request';
|
import request from 'utils/request';
|
||||||
|
|
||||||
class ShowAsset extends React.Component {
|
class ShowAsset extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
claimData: null,
|
error: null,
|
||||||
error : null,
|
|
||||||
};
|
};
|
||||||
this.getLongClaimId = this.getLongClaimId.bind(this);
|
this.getLongClaimId = this.getLongClaimId.bind(this);
|
||||||
this.getClaimData = this.getClaimData.bind(this);
|
this.getClaimData = this.getClaimData.bind(this);
|
||||||
|
@ -16,18 +15,19 @@ class ShowAsset extends React.Component {
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
console.log('ShowAsset did mount');
|
console.log('ShowAsset did mount');
|
||||||
console.log('ShowAsset props', this.props);
|
console.log('ShowAsset props', this.props);
|
||||||
|
const modifier = this.props.request.modifier;
|
||||||
|
const name = this.props.request.claim;
|
||||||
|
// create request params
|
||||||
let body = {};
|
let body = {};
|
||||||
if (this.props.identifier) {
|
if (modifier) {
|
||||||
if (this.props.identifier.isChannel) {
|
if (modifier.channel) {
|
||||||
body['channelName'] = this.props.identifier.channelName;
|
body['channelName'] = modifier.channel.name;
|
||||||
body['channelClaimId'] = this.props.identifier.channelClaimId;
|
body['channelClaimId'] = modifier.channel.id;
|
||||||
} else {
|
} else {
|
||||||
body['claimId'] = this.props.identifier.claimId;
|
body['claimId'] = modifier.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.props.claim) {
|
body['claimName'] = name;
|
||||||
body['claimName'] = this.props.claim.claimName;
|
|
||||||
}
|
|
||||||
const params = {
|
const params = {
|
||||||
method : 'POST',
|
method : 'POST',
|
||||||
headers: new Headers({
|
headers: new Headers({
|
||||||
|
@ -35,13 +35,14 @@ class ShowAsset extends React.Component {
|
||||||
}),
|
}),
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
}
|
}
|
||||||
|
// make request
|
||||||
const that = this;
|
const that = this;
|
||||||
this.getLongClaimId(params)
|
this.getLongClaimId(params)
|
||||||
.then(claimLongId => {
|
.then(claimLongId => {
|
||||||
return that.getClaimData(this.props.claim.claimName, claimLongId);
|
return that.getClaimData(name, claimLongId);
|
||||||
})
|
})
|
||||||
.then(claimData => {
|
.then(claimData => {
|
||||||
this.setState({ claimData });
|
this.props.onClaimDataChange(claimData);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
this.setState({error});
|
this.setState({error});
|
||||||
|
@ -81,26 +82,21 @@ class ShowAsset extends React.Component {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
render () {
|
render () {
|
||||||
if (this.props.isServeRequest) {
|
if (this.props.request.extension) {
|
||||||
return (
|
return (
|
||||||
<ShowAssetLite
|
<ShowAssetLite
|
||||||
error={this.state.error}
|
error={this.state.error}
|
||||||
claimData={this.state.claimData}
|
claimData={this.props.claim}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<ShowAssetDetails
|
<ShowAssetDetails
|
||||||
error={this.state.error}
|
error={this.state.error}
|
||||||
claimData={this.state.claimData}
|
claimData={this.props.claim}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// required props
|
|
||||||
// identifier
|
|
||||||
// claim
|
|
||||||
// isServeRequest
|
|
||||||
|
|
||||||
export default ShowAsset;
|
export default ShowAsset;
|
|
@ -1,6 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ErrorPage from 'components/ErrorPage';
|
import ErrorPage from 'components/ErrorPage';
|
||||||
import ShowAsset from 'components/ShowAsset';
|
import ShowAsset from 'containers/ShowAsset';
|
||||||
import ShowChannel from 'containers/ShowChannel';
|
import ShowChannel from 'containers/ShowChannel';
|
||||||
import lbryUri from 'utils/lbryUri';
|
import lbryUri from 'utils/lbryUri';
|
||||||
|
|
||||||
|
@ -109,11 +109,7 @@ class ShowPage extends React.Component {
|
||||||
);
|
);
|
||||||
} else if (this.props.request.claim) {
|
} else if (this.props.request.claim) {
|
||||||
return (
|
return (
|
||||||
<ShowAsset
|
<ShowAsset />
|
||||||
modifier={this.props.request.claim.identifier}
|
|
||||||
claim={this.props.request.claim.name}
|
|
||||||
extension={this.props.request.claim.extension}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,7 @@ const initialState = {
|
||||||
totalClaims: null,
|
totalClaims: null,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
claim: {
|
claim: null,
|
||||||
name: null,
|
|
||||||
id : null,
|
|
||||||
data: null,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -64,7 +60,7 @@ export default function (state = initialState, action) {
|
||||||
});
|
});
|
||||||
case actions.CLAIM_DATA_UPDATE:
|
case actions.CLAIM_DATA_UPDATE:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
displayClaim: action.claimData,
|
claim: action.data,
|
||||||
});
|
});
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
|
|
Loading…
Reference in a new issue