re-organized request parsing
This commit is contained in:
parent
c38eeb9850
commit
1a47296e24
2 changed files with 21 additions and 23 deletions
|
@ -3,26 +3,33 @@ import ErrorPage from 'components/ErrorPage';
|
|||
import ShowAssetLite from 'components/ShowAssetLite';
|
||||
import ShowAssetDetails from 'components/ShowAssetDetails';
|
||||
|
||||
import { ASSET } from 'constants/show_request_types';
|
||||
|
||||
function requestIsAnAssetRequest ({ requestType }) {
|
||||
return requestType === ASSET;
|
||||
}
|
||||
|
||||
function requestIsNewRequest (nextProps, props) {
|
||||
return (nextProps.requestId !== props.requestId);
|
||||
}
|
||||
|
||||
class ShowAsset extends React.Component {
|
||||
componentDidMount () {
|
||||
const { requestId, requestName, requestModifier, assetRequests } = this.props;
|
||||
// check to see if we have this asset
|
||||
if (assetRequests[requestId]) { // case: the assetRequest exists
|
||||
const request = assetRequests[requestId];
|
||||
this.onRepeatRequest(requestId, request);
|
||||
const existingRequest = assetRequests[requestId];
|
||||
if (existingRequest) { // case: the assetRequest exists
|
||||
this.onRepeatRequest(existingRequest);
|
||||
} else { // case: the asset request does not exist
|
||||
this.onNewRequest(requestId, requestName, requestModifier);
|
||||
}
|
||||
}
|
||||
componentWillReceiveProps (nextProps) {
|
||||
// case where componentDidMount triggered new props
|
||||
if (nextProps.assetRequests !== this.props.assetRequests) { // note: reason for not showing small url requests?
|
||||
console.log('show.assetRequests updated');
|
||||
if (requestIsAnAssetRequest(nextProps) && requestIsNewRequest(nextProps, this.props)) {
|
||||
const { requestId, requestName, requestModifier, assetRequests } = nextProps;
|
||||
// if the component received new assetRequests, check again to see if the current request matches one
|
||||
if (assetRequests[requestId]) { // case: the assetRequest exists
|
||||
const request = assetRequests[requestId];
|
||||
this.onRepeatRequest(request);
|
||||
const existingRequest = assetRequests[requestId];
|
||||
if (existingRequest) { // case: the assetRequest exists
|
||||
this.onRepeatRequest(existingRequest);
|
||||
} else { // case: the asset request does not exist
|
||||
this.onNewRequest(requestId, requestName, requestModifier);
|
||||
}
|
||||
|
|
|
@ -9,42 +9,33 @@ function requestIsAChannelRequest ({ requestType }) {
|
|||
return requestType === CHANNEL;
|
||||
}
|
||||
|
||||
function channelNameOrIdChanged (nextProps, props) {
|
||||
return (nextProps.requestChannelName !== props.requestChannelName || nextProps.requestChannelName !== props.requestChannelName);
|
||||
function requestIsNewRequest (nextProps, props) {
|
||||
return (nextProps.requestId !== props.requestId);
|
||||
}
|
||||
|
||||
class ShowChannel extends React.Component {
|
||||
componentDidMount () {
|
||||
console.log('showchannel did mount');
|
||||
const {requestId, requestChannelName, requestChannelId, requestList} = this.props;
|
||||
const existingRequest = requestList[requestId];
|
||||
if (existingRequest) {
|
||||
console.log('we got a repeat channel request on an unmounted ShowChannel component');
|
||||
this.onRepeatChannelRequest(existingRequest);
|
||||
} else {
|
||||
this.onNewChannelRequest(requestId, requestChannelName, requestChannelId);
|
||||
}
|
||||
}
|
||||
componentWillReceiveProps (nextProps) {
|
||||
console.log('showchannel will receive new props');
|
||||
if (requestIsAChannelRequest(nextProps) && channelNameOrIdChanged(nextProps, this.props)) {
|
||||
if (requestIsAChannelRequest(nextProps) && requestIsNewRequest(nextProps, this.props)) {
|
||||
const {requestId, requestChannelName, requestChannelId, requestList} = nextProps;
|
||||
const existingRequest = requestList[requestId];
|
||||
if (existingRequest) {
|
||||
this.onRepeatChannelRequest(existingRequest);
|
||||
} else {
|
||||
console.log('we got a new channel request on a mounted ShowChannel component');
|
||||
this.onNewChannelRequest(requestId, requestChannelName, requestChannelId);
|
||||
}
|
||||
};
|
||||
}
|
||||
onNewChannelRequest (requestId, requestName, requestChannelId) {
|
||||
// validate the request (i.e. get channel full claim id)
|
||||
// update teh request list
|
||||
// if error, return early (set the request error in the store)
|
||||
// if the request is valid...
|
||||
// add it to the requestList
|
||||
// update showChannel to reflect the channel details
|
||||
console.log('new request');
|
||||
this.props.onNewChannelRequest(requestId, requestName, requestChannelId);
|
||||
}
|
||||
onRepeatChannelRequest ({ id, error, name, claimId }) {
|
||||
|
|
Loading…
Reference in a new issue