From 1a47296e24363662be03c7bd165fd3f1b10b0ee0 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 7 Feb 2018 23:18:18 -0800 Subject: [PATCH] re-organized request parsing --- react/containers/ShowAsset/view.jsx | 27 +++++++++++++++++---------- react/containers/ShowChannel/view.jsx | 17 ++++------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/react/containers/ShowAsset/view.jsx b/react/containers/ShowAsset/view.jsx index fd0b4f8e..fd392835 100644 --- a/react/containers/ShowAsset/view.jsx +++ b/react/containers/ShowAsset/view.jsx @@ -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); } diff --git a/react/containers/ShowChannel/view.jsx b/react/containers/ShowChannel/view.jsx index 1dc0fd27..b494c123 100644 --- a/react/containers/ShowChannel/view.jsx +++ b/react/containers/ShowChannel/view.jsx @@ -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 }) {