2018-01-31 02:15:23 +01:00
|
|
|
import React from 'react';
|
2018-02-07 20:30:39 +01:00
|
|
|
import ErrorPage from 'components/ErrorPage';
|
2018-02-02 20:10:58 +01:00
|
|
|
import ShowAssetLite from 'components/ShowAssetLite';
|
|
|
|
import ShowAssetDetails from 'components/ShowAssetDetails';
|
2018-01-31 02:15:23 +01:00
|
|
|
|
2018-02-08 03:01:51 +01:00
|
|
|
function buildIdFromModifierObject (name, modifier) {
|
2018-02-07 22:26:07 +01:00
|
|
|
if (modifier) {
|
|
|
|
if (modifier.channel.name) {
|
2018-02-08 03:01:51 +01:00
|
|
|
return `${name}#${modifier.channel.name}#${modifier.channel.id}`;
|
2018-02-07 22:26:07 +01:00
|
|
|
}
|
2018-02-08 03:01:51 +01:00
|
|
|
return `${name}#${modifier.id}`;
|
2018-02-07 22:26:07 +01:00
|
|
|
}
|
2018-02-08 03:01:51 +01:00
|
|
|
return `${name}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
function buildIdFromNameAndClaimId (name, claimId) {
|
|
|
|
return `${name}#${claimId}`;
|
2018-02-07 22:26:07 +01:00
|
|
|
}
|
|
|
|
|
2018-01-31 02:15:23 +01:00
|
|
|
class ShowAsset extends React.Component {
|
|
|
|
componentDidMount () {
|
2018-02-08 03:01:51 +01:00
|
|
|
const { requestName, requestModifier, assetRequests } = this.props;
|
|
|
|
const id = buildIdFromModifierObject(requestName, requestModifier);
|
2018-02-07 22:26:07 +01:00
|
|
|
// check to see if we have this asset
|
2018-02-08 03:01:51 +01:00
|
|
|
if (assetRequests[id]) { // case: the assetRequest exists
|
|
|
|
const request = assetRequests[id];
|
|
|
|
this.onRepeatRequest(id, request);
|
|
|
|
} else { // case: the asset request does not exist
|
|
|
|
this.onNewRequest(id, requestName, requestModifier);
|
2018-01-31 02:15:23 +01:00
|
|
|
}
|
|
|
|
}
|
2018-02-08 03:01:51 +01:00
|
|
|
componentWillReceiveProps (nextProps) {
|
|
|
|
if (nextProps.assetRequests !== this.props.assetRequests) {
|
|
|
|
console.log('assetRequests updated:');
|
|
|
|
const { requestName, requestModifier, assetRequests } = nextProps;
|
|
|
|
const id = buildIdFromModifierObject(requestName, requestModifier);
|
|
|
|
// if the component received new assetRequests, check again to see if the current request matches one
|
|
|
|
if (assetRequests[id]) { // case: the assetRequest exists
|
|
|
|
const request = assetRequests[id];
|
|
|
|
this.onRepeatRequest(id, request);
|
|
|
|
} else { // case: the asset request does not exist
|
|
|
|
this.onNewRequest(id, requestName, requestModifier);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onNewRequest (id, requestName, requestModifier) {
|
|
|
|
console.log('new request');
|
|
|
|
this.props.onNewRequest(id, requestName, requestModifier);
|
|
|
|
}
|
|
|
|
onRepeatRequest (requestId, request) {
|
|
|
|
console.log('repeat request');
|
|
|
|
const { assets } = this.props;
|
|
|
|
const { error: requestError, name, claimId } = request;
|
|
|
|
const assetId = buildIdFromNameAndClaimId(name, claimId);
|
|
|
|
// if error, return and update state with error
|
|
|
|
if (requestError) {
|
|
|
|
return this.props.onRequestError(requestError);
|
|
|
|
}
|
|
|
|
// update the show asset data in the store
|
|
|
|
if (assets[assetId]) { // case: the asset data already exists
|
|
|
|
let { error, name, claimId, shortId, claimData } = assets[assetId];
|
|
|
|
this.props.onShowExistingAsset(assetId, error, name, claimId, shortId, claimData);
|
|
|
|
} else { // case: the asset data does not exist yet
|
|
|
|
this.props.onShowNewAsset(assetId, name, claimId);
|
|
|
|
}
|
2018-01-31 02:15:23 +01:00
|
|
|
}
|
2018-02-05 01:40:28 +01:00
|
|
|
componentWillUnmount () {
|
2018-02-08 03:01:51 +01:00
|
|
|
this.props.onLeaveShowAsset();
|
2018-02-05 01:40:28 +01:00
|
|
|
}
|
2018-01-31 02:15:23 +01:00
|
|
|
render () {
|
2018-02-08 03:01:51 +01:00
|
|
|
const { error, name, requestExtension } = this.props;
|
2018-02-07 19:52:09 +01:00
|
|
|
if (error) {
|
|
|
|
return (
|
2018-02-07 20:30:39 +01:00
|
|
|
<ErrorPage error={error}/>
|
2018-02-07 19:52:09 +01:00
|
|
|
);
|
|
|
|
}
|
2018-02-08 03:01:51 +01:00
|
|
|
if (name) {
|
|
|
|
if (requestExtension) {
|
2018-02-05 02:51:17 +01:00
|
|
|
return (
|
2018-02-07 19:52:09 +01:00
|
|
|
<ShowAssetLite />
|
2018-02-05 02:51:17 +01:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
2018-02-07 19:52:09 +01:00
|
|
|
<ShowAssetDetails />
|
2018-02-05 02:51:17 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
2018-01-31 02:15:23 +01:00
|
|
|
return (
|
2018-02-07 19:52:09 +01:00
|
|
|
<div> </div>
|
2018-01-31 02:15:23 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ShowAsset;
|