debugged state mismatch
This commit is contained in:
parent
d219cbf1a2
commit
d1a71cf74f
6 changed files with 71 additions and 63 deletions
|
@ -9,16 +9,19 @@ export function updateRequestError (error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateRequestWithChannelRequest (name, id) {
|
export function updateRequestWithChannelRequest (name, id) {
|
||||||
|
const requestId = `cr#${name}#${id}`;
|
||||||
return {
|
return {
|
||||||
type: actions.REQUEST_CHANNEL_UPDATE,
|
type: actions.REQUEST_CHANNEL_UPDATE,
|
||||||
data: { name, id },
|
data: { requestId, name, id },
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function updateRequestWithAssetRequest (name, id, channelName, channelId, extension) {
|
export function updateRequestWithAssetRequest (name, id, channelName, channelId, extension) {
|
||||||
|
const requestId = `ar#${name}#${id}#${channelName}#${channelId}`;
|
||||||
return {
|
return {
|
||||||
type: actions.REQUEST_CLAIM_UPDATE,
|
type: actions.REQUEST_CLAIM_UPDATE,
|
||||||
data: {
|
data: {
|
||||||
|
requestId,
|
||||||
name,
|
name,
|
||||||
modifier: {
|
modifier: {
|
||||||
id,
|
id,
|
||||||
|
|
|
@ -5,15 +5,17 @@ import { newAssetRequest, updateRequestError, showNewAsset, updateShowAsset, cle
|
||||||
const mapStateToProps = ({ show }) => {
|
const mapStateToProps = ({ show }) => {
|
||||||
return {
|
return {
|
||||||
// new
|
// new
|
||||||
requestName : show.assetRequest.name,
|
requestId : show.request.id,
|
||||||
requestModifier : show.assetRequest.modifier,
|
requestName : show.request.data.name,
|
||||||
requestExtension: show.assetRequest.extension,
|
requestModifier : show.request.data.modifier,
|
||||||
|
requestExtension: show.request.data.extension,
|
||||||
assetRequests : show.assetRequests,
|
assetRequests : show.assetRequests,
|
||||||
assets : show.assets,
|
assets : show.assets,
|
||||||
// old
|
// old
|
||||||
error : show.showAsset.error,
|
error : show.showAsset.error,
|
||||||
name : show.showAsset.name,
|
name : show.showAsset.name,
|
||||||
claimData : show.showAsset.claimData,
|
claimData : show.showAsset.claimData,
|
||||||
|
showAsset : show.assets[show.request.id],
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,44 +3,31 @@ 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';
|
||||||
|
|
||||||
function buildIdFromModifierObject (name, modifier) {
|
|
||||||
if (modifier) {
|
|
||||||
if (modifier.channel.name) {
|
|
||||||
return `${name}#${modifier.channel.name}#${modifier.channel.id}`;
|
|
||||||
}
|
|
||||||
return `${name}#${modifier.id}`;
|
|
||||||
}
|
|
||||||
return `${name}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildIdFromNameAndClaimId (name, claimId) {
|
|
||||||
return `${name}#${claimId}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
class ShowAsset extends React.Component {
|
class ShowAsset extends React.Component {
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
const { requestName, requestModifier, assetRequests } = this.props;
|
const { requestId, requestName, requestModifier, assetRequests } = this.props;
|
||||||
const id = buildIdFromModifierObject(requestName, requestModifier);
|
|
||||||
// check to see if we have this asset
|
// check to see if we have this asset
|
||||||
if (assetRequests[id]) { // case: the assetRequest exists
|
if (assetRequests[requestId]) { // case: the assetRequest exists
|
||||||
const request = assetRequests[id];
|
const request = assetRequests[requestId];
|
||||||
this.onRepeatRequest(id, request);
|
this.onRepeatRequest(requestId, request);
|
||||||
} else { // case: the asset request does not exist
|
} else { // case: the asset request does not exist
|
||||||
this.onNewRequest(id, requestName, requestModifier);
|
this.onNewRequest(requestId, requestName, requestModifier);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
componentWillReceiveProps (nextProps) {
|
componentWillReceiveProps (nextProps) {
|
||||||
if (nextProps.assetRequests !== this.props.assetRequests) {
|
// case where componentDidMount triggered new props
|
||||||
console.log('assetRequests updated:');
|
if (nextProps.assetRequests !== this.props.assetRequests) { // note: reason for not showing small url requests?
|
||||||
const { requestName, requestModifier, assetRequests } = nextProps;
|
console.log('show.assetRequests updated');
|
||||||
const id = buildIdFromModifierObject(requestName, requestModifier);
|
const { requestId, requestName, requestModifier, assetRequests } = nextProps;
|
||||||
// if the component received new assetRequests, check again to see if the current request matches one
|
// if the component received new assetRequests, check again to see if the current request matches one
|
||||||
if (assetRequests[id]) { // case: the assetRequest exists
|
if (assetRequests[requestId]) { // case: the assetRequest exists
|
||||||
const request = assetRequests[id];
|
const request = assetRequests[requestId];
|
||||||
this.onRepeatRequest(id, request);
|
this.onRepeatRequest(requestId, request);
|
||||||
} else { // case: the asset request does not exist
|
} else { // case: the asset request does not exist
|
||||||
this.onNewRequest(id, requestName, requestModifier);
|
this.onNewRequest(requestId, requestName, requestModifier);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.log('show.assetRequests did not update');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onNewRequest (id, requestName, requestModifier) {
|
onNewRequest (id, requestName, requestModifier) {
|
||||||
|
@ -51,7 +38,7 @@ class ShowAsset extends React.Component {
|
||||||
console.log('repeat request');
|
console.log('repeat request');
|
||||||
const { assets } = this.props;
|
const { assets } = this.props;
|
||||||
const { error: requestError, name, claimId } = request;
|
const { error: requestError, name, claimId } = request;
|
||||||
const assetId = buildIdFromNameAndClaimId(name, claimId);
|
const assetId = `a#${name}#${claimId}`;
|
||||||
// if error, return and update state with error
|
// if error, return and update state with error
|
||||||
if (requestError) {
|
if (requestError) {
|
||||||
return this.props.onRequestError(requestError);
|
return this.props.onRequestError(requestError);
|
||||||
|
@ -74,7 +61,7 @@ class ShowAsset extends React.Component {
|
||||||
<ErrorPage error={error}/>
|
<ErrorPage error={error}/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (name) {
|
if (name) { // direct requests are passing because name is present so it just goes
|
||||||
if (requestExtension) {
|
if (requestExtension) {
|
||||||
return (
|
return (
|
||||||
<ShowAssetLite />
|
<ShowAssetLite />
|
||||||
|
|
|
@ -4,12 +4,13 @@ import View from './view';
|
||||||
|
|
||||||
const mapStateToProps = ({ show }) => {
|
const mapStateToProps = ({ show }) => {
|
||||||
return {
|
return {
|
||||||
requestName: show.channelRequest.name,
|
requestId : show.request.id,
|
||||||
requestId : show.channelRequest.id,
|
requestChannelName: show.request.data.name,
|
||||||
error : show.showChannel.error,
|
requestChannelId : show.request.data.id,
|
||||||
name : show.showChannel.channelData.name,
|
error : show.showChannel.error,
|
||||||
shortId : show.showChannel.channelData.shortId,
|
name : show.showChannel.channelData.name,
|
||||||
longId : show.showChannel.channelData.longId,
|
shortId : show.showChannel.channelData.shortId,
|
||||||
|
longId : show.showChannel.channelData.longId,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -6,14 +6,18 @@ import request from 'utils/request';
|
||||||
|
|
||||||
class ShowChannel extends React.Component {
|
class ShowChannel extends React.Component {
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
this.getAndStoreChannelData(this.props.requestName, this.props.requestId);
|
console.log('showchannel did mount');
|
||||||
|
const {requestChannelName, requestChannelId} = this.props;
|
||||||
|
this.getAndStoreChannelData(requestChannelName, requestChannelId);
|
||||||
}
|
}
|
||||||
componentWillReceiveProps (nextProps) {
|
componentWillReceiveProps (nextProps) {
|
||||||
if (nextProps.requestName !== this.props.requestName || nextProps.requestId !== this.props.requestId) {
|
if (nextProps.channelRequests !== this.props.channelRequests) {
|
||||||
this.getAndStoreChannelData(nextProps.requestName, nextProps.requestId);
|
const {requestChannelName, requestChannelId} = nextProps;
|
||||||
|
this.getAndStoreChannelData(requestChannelName, requestChannelId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getAndStoreChannelData (name, id) {
|
getAndStoreChannelData (name, id) {
|
||||||
|
console.log('getting and storing channel data for channel:', name, id);
|
||||||
if (!id) id = 'none';
|
if (!id) id = 'none';
|
||||||
const url = `/api/channel/data/${name}/${id}`;
|
const url = `/api/channel/data/${name}/${id}`;
|
||||||
return request(url)
|
return request(url)
|
||||||
|
|
|
@ -4,24 +4,26 @@ import { LOCAL_CHECK, ERROR } from 'constants/asset_display_states';
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
request: {
|
request: {
|
||||||
error: null,
|
error : null,
|
||||||
type : null,
|
type : null,
|
||||||
},
|
data : null,
|
||||||
channelRequest: {
|
requestId: null,
|
||||||
name: null,
|
|
||||||
id : null,
|
|
||||||
},
|
|
||||||
assetRequest: {
|
|
||||||
name : null,
|
|
||||||
modifier: {
|
|
||||||
id : null,
|
|
||||||
channel: {
|
|
||||||
name: null,
|
|
||||||
id : null,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
extension: null,
|
|
||||||
},
|
},
|
||||||
|
// channelRequest: {
|
||||||
|
// name: null,
|
||||||
|
// id : null,
|
||||||
|
// },
|
||||||
|
// assetRequest: {
|
||||||
|
// name : null,
|
||||||
|
// modifier: {
|
||||||
|
// id : null,
|
||||||
|
// channel: {
|
||||||
|
// name: null,
|
||||||
|
// id : null,
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// extension: null,
|
||||||
|
// },
|
||||||
showChannel: {
|
showChannel: {
|
||||||
error : null,
|
error : null,
|
||||||
channelData: {
|
channelData: {
|
||||||
|
@ -71,21 +73,30 @@ export default function (state = initialState, action) {
|
||||||
request: {
|
request: {
|
||||||
type : CHANNEL,
|
type : CHANNEL,
|
||||||
error: null,
|
error: null,
|
||||||
|
id : action.data.requestId,
|
||||||
|
data : {
|
||||||
|
name: action.data.name,
|
||||||
|
id : action.data.id,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
channelRequest: action.data,
|
|
||||||
});
|
});
|
||||||
case actions.REQUEST_CLAIM_UPDATE:
|
case actions.REQUEST_CLAIM_UPDATE:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
request: {
|
request: {
|
||||||
type : ASSET,
|
type : ASSET,
|
||||||
error: null,
|
error: null,
|
||||||
|
id : action.data.requestId,
|
||||||
|
data : {
|
||||||
|
name : action.data.name,
|
||||||
|
modifier : action.data.modifier,
|
||||||
|
extension: action.data.extension,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
assetRequest: action.data,
|
|
||||||
});
|
});
|
||||||
// request for an asset
|
// request for an asset
|
||||||
case actions.ASSET_REQUEST_ADD:
|
case actions.ASSET_REQUEST_ADD:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
assetRequests: Object.assign({}, state.assets, {
|
assetRequests: Object.assign({}, state.assetRequests, {
|
||||||
[action.data.id]: {
|
[action.data.id]: {
|
||||||
error : action.data.error,
|
error : action.data.error,
|
||||||
name : action.data.name,
|
name : action.data.name,
|
||||||
|
|
Loading…
Add table
Reference in a new issue