re-organized request parsing

This commit is contained in:
bill bittner 2018-02-07 23:18:18 -08:00
parent c38eeb9850
commit 1a47296e24
2 changed files with 21 additions and 23 deletions

View file

@ -3,26 +3,33 @@ import ErrorPage from 'components/ErrorPage';
import ShowAssetLite from 'components/ShowAssetLite'; import ShowAssetLite from 'components/ShowAssetLite';
import ShowAssetDetails from 'components/ShowAssetDetails'; 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 { class ShowAsset extends React.Component {
componentDidMount () { componentDidMount () {
const { requestId, requestName, requestModifier, assetRequests } = this.props; const { requestId, requestName, requestModifier, assetRequests } = this.props;
// check to see if we have this asset const existingRequest = assetRequests[requestId];
if (assetRequests[requestId]) { // case: the assetRequest exists if (existingRequest) { // case: the assetRequest exists
const request = assetRequests[requestId]; this.onRepeatRequest(existingRequest);
this.onRepeatRequest(requestId, request);
} else { // case: the asset request does not exist } else { // case: the asset request does not exist
this.onNewRequest(requestId, requestName, requestModifier); this.onNewRequest(requestId, requestName, requestModifier);
} }
} }
componentWillReceiveProps (nextProps) { componentWillReceiveProps (nextProps) {
// case where componentDidMount triggered new props // case where componentDidMount triggered new props
if (nextProps.assetRequests !== this.props.assetRequests) { // note: reason for not showing small url requests? if (requestIsAnAssetRequest(nextProps) && requestIsNewRequest(nextProps, this.props)) {
console.log('show.assetRequests updated');
const { requestId, requestName, requestModifier, assetRequests } = nextProps; const { requestId, requestName, requestModifier, assetRequests } = nextProps;
// if the component received new assetRequests, check again to see if the current request matches one const existingRequest = assetRequests[requestId];
if (assetRequests[requestId]) { // case: the assetRequest exists if (existingRequest) { // case: the assetRequest exists
const request = assetRequests[requestId]; this.onRepeatRequest(existingRequest);
this.onRepeatRequest(request);
} else { // case: the asset request does not exist } else { // case: the asset request does not exist
this.onNewRequest(requestId, requestName, requestModifier); this.onNewRequest(requestId, requestName, requestModifier);
} }

View file

@ -9,42 +9,33 @@ function requestIsAChannelRequest ({ requestType }) {
return requestType === CHANNEL; return requestType === CHANNEL;
} }
function channelNameOrIdChanged (nextProps, props) { function requestIsNewRequest (nextProps, props) {
return (nextProps.requestChannelName !== props.requestChannelName || nextProps.requestChannelName !== props.requestChannelName); return (nextProps.requestId !== props.requestId);
} }
class ShowChannel extends React.Component { class ShowChannel extends React.Component {
componentDidMount () { componentDidMount () {
console.log('showchannel did mount');
const {requestId, requestChannelName, requestChannelId, requestList} = this.props; const {requestId, requestChannelName, requestChannelId, requestList} = this.props;
const existingRequest = requestList[requestId]; const existingRequest = requestList[requestId];
if (existingRequest) { if (existingRequest) {
console.log('we got a repeat channel request on an unmounted ShowChannel component');
this.onRepeatChannelRequest(existingRequest); this.onRepeatChannelRequest(existingRequest);
} else { } else {
this.onNewChannelRequest(requestId, requestChannelName, requestChannelId); this.onNewChannelRequest(requestId, requestChannelName, requestChannelId);
} }
} }
componentWillReceiveProps (nextProps) { componentWillReceiveProps (nextProps) {
console.log('showchannel will receive new props'); if (requestIsAChannelRequest(nextProps) && requestIsNewRequest(nextProps, this.props)) {
if (requestIsAChannelRequest(nextProps) && channelNameOrIdChanged(nextProps, this.props)) {
const {requestId, requestChannelName, requestChannelId, requestList} = nextProps; const {requestId, requestChannelName, requestChannelId, requestList} = nextProps;
const existingRequest = requestList[requestId]; const existingRequest = requestList[requestId];
if (existingRequest) { if (existingRequest) {
this.onRepeatChannelRequest(existingRequest); this.onRepeatChannelRequest(existingRequest);
} else { } else {
console.log('we got a new channel request on a mounted ShowChannel component');
this.onNewChannelRequest(requestId, requestChannelName, requestChannelId); this.onNewChannelRequest(requestId, requestChannelName, requestChannelId);
} }
}; };
} }
onNewChannelRequest (requestId, requestName, requestChannelId) { onNewChannelRequest (requestId, requestName, requestChannelId) {
// validate the request (i.e. get channel full claim id) console.log('new request');
// 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
this.props.onNewChannelRequest(requestId, requestName, requestChannelId); this.props.onNewChannelRequest(requestId, requestName, requestChannelId);
} }
onRepeatChannelRequest ({ id, error, name, claimId }) { onRepeatChannelRequest ({ id, error, name, claimId }) {