added short id to redux

This commit is contained in:
bill bittner 2018-02-04 17:43:02 -08:00
parent 0a541b6dd9
commit c4a77f0317
7 changed files with 45 additions and 23 deletions

View file

@ -39,9 +39,10 @@ export function updateChannelClaimsData (claims, currentPage, totalPages, totalC
};
};
export function updateAssetClaimData (data) {
export function updateAssetClaimData (data, shortId) {
return {
type: actions.ASSET_CLAIM_DATA_UPDATE,
data,
shortId,
};
};

View file

@ -161,13 +161,11 @@ class AssetInfo extends React.Component {
}
};
// required props
// {channelName, certificateId, description, shortClaimId, name, fileExt, claimId, contentType, thumbnail, host}
AssetInfo.propTypes = {
channelName : PropTypes.string,
certificateId: PropTypes.string,
description : PropTypes.string,
// shortClaimId : PropsTypes.string.isRequired,
shortId : PropTypes.string.isRequired,
name : PropTypes.string.isRequired,
claimId : PropTypes.string.isRequired,
contentType : PropTypes.string.isRequired,

View file

@ -42,11 +42,11 @@ class ShowAssetDetails extends React.Component {
description={this.props.claimData.description}
name={this.props.claimData.name}
claimId={this.props.claimData.claimId}
shortClaimId={this.props.claimData.shortClaimId}
fileExt={this.props.claimData.fileExt}
contentType={this.props.claimData.contentType}
thumbnail={this.props.claimData.thumbnail}
host={this.props.claimData.host}
shortClaimId={this.props.shortId}
/>
</div>
</div>
@ -60,7 +60,7 @@ class ShowAssetDetails extends React.Component {
ShowAssetDetails.propTypes = {
error : PropTypes.string,
claimData: PropTypes.object.isRequired,
// shortUrl: PropTypes.string.isRequired,
shortId : PropTypes.string.isRequired,
};
export default ShowAssetDetails;

View file

@ -7,17 +7,18 @@ const mapStateToProps = ({ show }) => {
modifier : show.assetRequest.modifier,
claim : show.assetRequest.name,
extension: show.assetRequest.extension,
claimData: show.showAsset.claimData,
claimData: show.showAsset.claimData.data,
shortId : show.showAsset.claimData.shortId,
};
};
const mapDispatchToProps = dispatch => {
return {
onAssetClaimDataUpdate: (claimData) => {
dispatch(updateAssetClaimData(claimData));
onAssetClaimDataUpdate: (claimData, shortId) => {
dispatch(updateAssetClaimData(claimData, shortId));
},
onAssetClaimDataClear: () => {
dispatch(updateAssetClaimData(null));
dispatch(updateAssetClaimData(null, null));
},
};
};

View file

@ -39,11 +39,11 @@ class ShowAsset extends React.Component {
const that = this;
this.getLongClaimId(params)
.then(claimLongId => {
return that.getClaimData(name, claimLongId);
return Promise.all([that.getShortClaimId(claimLongId, name), that.getClaimData(claimLongId, name)]);
})
.then(claimData => {
.then(([shortId, claimData]) => {
this.setState({error: null}); // note: move this to redux level
this.props.onAssetClaimDataUpdate(claimData);
this.props.onAssetClaimDataUpdate(claimData, shortId);
})
.catch(error => {
this.setState({error});
@ -54,19 +54,35 @@ class ShowAsset extends React.Component {
console.log('params:', params);
return new Promise((resolve, reject) => {
request(url, params)
.then(({ success, message }) => {
.then(({ success, message, data }) => {
console.log('get long claim id response:', message);
if (!success) {
reject(message);
}
resolve(message);
resolve(data);
})
.catch((error) => {
reject(error.message);
});
});
}
getClaimData (claimName, claimId) {
getShortClaimId (longId, name) {
const url = `/api/claim-shorten-id/${longId}/${name}`;
return new Promise((resolve, reject) => {
request(url)
.then(({ success, message, data }) => {
console.log('get short claim id response:', data);
if (!success) {
reject(message);
}
resolve(data);
})
.catch((error) => {
reject(error.message);
});
});
}
getClaimData (claimId, claimName) {
return new Promise((resolve, reject) => {
const url = `/api/claim-get-data/${claimName}/${claimId}`;
return request(url)
@ -98,7 +114,7 @@ class ShowAsset extends React.Component {
<ShowAssetDetails
error={this.state.error}
claimData={this.props.claimData}
// shortUrl={this.props.shortUrl}
shortId={this.props.shortId}
/>
)}
</div>

View file

@ -32,7 +32,10 @@ const initialState = {
},
},
showAsset: {
claimData: null,
claimData: {
data : null,
shortId: null,
},
},
};
@ -68,7 +71,7 @@ export default function (state = initialState, action) {
case actions.CHANNEL_DATA_UPDATE:
return Object.assign({}, state, {
showChannel: Object.assign({}, state.showChannel, {
channelData: Object.assign({}, state.channel, {
channelData: Object.assign({}, state.channelData, {
name : action.name,
shortId: action.shortId,
longId : action.longId,
@ -89,7 +92,10 @@ export default function (state = initialState, action) {
case actions.ASSET_CLAIM_DATA_UPDATE:
return Object.assign({}, state, {
showAsset: {
claimData: action.data,
claimData: {
data : action.data,
shortId: action.shortId,
},
},
});
default:

View file

@ -172,11 +172,11 @@ module.exports = (app) => {
app.get('/api/claim-shorten-id/:longId/:name', ({ params }, res) => {
db.Claim.getShortClaimIdFromLongClaimId(params.longId, params.name)
.then(shortId => {
res.status(200).json(shortId);
res.status(200).json({success: true, data: shortId});
})
.catch(error => {
logger.error('api error getting short channel id', error);
res.status(400).json(error.message);
res.status(200).json({success: false, message: error.message});
});
});
// route to get a short channel id from long channel Id
@ -238,7 +238,7 @@ module.exports = (app) => {
if (result === NO_CLAIM) {
return res.status(200).json({success: false, message: 'No matching claim id could be found'});
}
res.status(200).json({success: true, message: result});
res.status(200).json({success: true, data: result});
})
.catch(error => {
logger.error('api error getting long claim id', error);