spee.ch/react/containers/ShowAsset/view.jsx

68 lines
1.9 KiB
React
Raw Normal View History

import React from 'react';
import ErrorPage from 'components/ErrorPage';
import ShowAssetLite from 'components/ShowAssetLite';
import ShowAssetDetails from 'components/ShowAssetDetails';
import request from 'utils/request';
2018-02-07 22:26:07 +01:00
function buildIdFromModifierObject (modifier) {
if (modifier) {
if (modifier.channel.name) {
return `${modifier.channel.name}#${modifier.channel.id}`;
}
return modifier.id;
}
return '';
}
class ShowAsset extends React.Component {
constructor (props) {
super(props);
this.getLongClaimId = this.getLongClaimId.bind(this);
this.getClaimData = this.getClaimData.bind(this);
}
componentDidMount () {
2018-02-07 22:26:07 +01:00
const { request: { name, modifier }, assetRequests } = this.props;
const id = buildIdFromModifierObject(modifier);
// check to see if we have this asset
if (assetRequests[id]) {
// case: the assetRequest exists
this.props.onNewAssetRequest(id, name, modifier); // request the long id and update the store with a new asset request record.
} else {
// case: the asset request does not exist
this.onRepeatAssetRequest(name, modifier); // get the asset request record...?
}
}
2018-02-07 22:26:07 +01:00
onRepeatAssetRequest (id, modifier, assetRequests) {
// get the results of the existing asset request
const {error, claimId} = assetRequests[id];
console.log(`results form past request ${id}:`, error, claimId);
}
2018-02-05 01:40:28 +01:00
componentWillUnmount () {
this.props.onAssetClaimDataClear();
}
render () {
const { error, claimData, extension } = this.props;
if (error) {
return (
<ErrorPage error={error}/>
);
}
if (claimData) {
if (extension) {
2018-02-05 02:51:17 +01:00
return (
<ShowAssetLite />
2018-02-05 02:51:17 +01:00
);
} else {
return (
<ShowAssetDetails />
2018-02-05 02:51:17 +01:00
);
}
};
return (
<div> </div>
);
}
};
export default ShowAsset;