debugged channel update reducer

This commit is contained in:
bill bittner 2018-02-08 11:50:30 -08:00
parent 0a3e052564
commit 967474bfa4
8 changed files with 37 additions and 42 deletions

View file

@ -100,17 +100,17 @@ export function addChannelRequest (id, error, name, longId, shortId) {
// show a channel
export function showNewChannel (id, name, longId, channelData) {
export function showNewChannel (id, channelData) {
return {
type: actions.SHOW_CHANNEL_NEW,
data: { id, name, longId, channelData },
data: { id, channelData },
};
};
export function updateShowChannel (error, channelData, claimData) {
export function updateShowChannel (error, name, shortId, longId, claimData) {
return {
type: actions.SHOW_CHANNEL_UPDATE,
data: { error, channelData, claimData },
data: { error, name, shortId, longId, claimData },
};
};

View file

@ -2,26 +2,15 @@ import Request from 'utils/request';
import request from '../utils/request';
export function getChannelData (name, id) {
console.log('getting and storing channel data for channel:', name, id);
console.log('getting channel data for channel:', name, id);
if (!id) id = 'none';
const url = `/api/channel/data/${name}/${id}`;
return request(url);
};
export function getChannelClaims (name, longId, page) {
console.log('getting and storing channel claims for channel:', name, longId);
console.log('getting channel claims for channel:', name, longId);
if (!page) page = 1;
const url = `/api/channel/claims/${name}/${longId}/${page}`;
return Request(url);
// .then(({ success, message, data }) => {
// console.log('api/channel-claims response:', data);
// if (!success) {
// return this.setState({error: message});
// }
// this.setState({error: null}); // move this error to redux state
// this.props.onChannelClaimsDataUpdate(data.claims, data.currentPage, data.totalPages, data.totalResults);
// })
// .catch((error) => {
// this.setState({error: error.message});
// });
};

View file

@ -10,7 +10,7 @@ const mapStateToProps = ({ show }) => {
requestModifier : show.request.data.modifier,
requestExtension: show.request.data.extension,
assetRequests : show.assetRequests,
assets : show.assets,
assetList : show.assetList,
// show asset
error : show.showAsset.error,
name : show.showAsset.name,

View file

@ -48,9 +48,9 @@ class ShowAsset extends React.Component {
return this.props.onRequestError(error);
}
// update the showAsset data in the store
const { assets } = this.props;
const { assetList } = this.props;
const assetId = `a#${name}#${claimId}`;
const existingAssetRecord = assets[assetId];
const existingAssetRecord = assetList[assetId];
if (existingAssetRecord) { // case: the asset data already exists
this.showExistingAsset(existingAssetRecord);
} else { // case: the asset data does not exist yet

View file

@ -27,11 +27,11 @@ const mapDispatchToProps = dispatch => {
onRequestError: (error) => {
dispatch(updateRequestError(error, null, null));
},
onShowNewChannel: (id, name, longId) => {
dispatch(showNewChannel(id, name, longId));
onShowNewChannel: (id, channelData) => {
dispatch(showNewChannel(id, channelData));
},
onShowExistingChannel: (error, channelData, claimData) => {
dispatch(updateShowChannel(error, channelData, claimData));
onShowExistingChannel: (error, name, shortId, longId, claimData) => {
dispatch(updateShowChannel(error, name, shortId, longId, claimData));
},
onShowChannelClear: () => {
dispatch(clearShowChannel());

View file

@ -49,17 +49,18 @@ class ShowChannel extends React.Component {
if (existingChannel) {
this.showExistingChannel(channelRecordId, existingChannel);
} else {
this.showNewChannel(channelRecordId, channelData.name, channelData.longId, channelData);
this.showNewChannel(channelRecordId, channelData);
}
}
showNewChannel (channelRecordId, name, longId) {
this.props.onShowNewChannel(channelRecordId, name, longId);
showNewChannel (channelRecordId, channelData) {
this.props.onShowNewChannel(channelRecordId, channelData);
};
showExistingChannel (existingChannel) {
const { error, channelData, claimData } = existingChannel;
this.props.onShowExistingChannel(error, channelData, claimData);
const { error, channelData: {name, shortId, longId}, claimData } = existingChannel;
this.props.onShowExistingChannel(error, name, shortId, longId, claimData);
};
componentWillUnmount () {
console.log('ShowChannel will unmount');
this.props.onShowChannelClear();
}
render () {

View file

@ -37,7 +37,7 @@ const initialState = {
channelRequests: {},
channelList : {},
assetRequests : {},
assets : {}, // same schema as showAsset
assetList : {}, // same schema as showAsset
};
/*
@ -141,9 +141,13 @@ export default function (state = initialState, action) {
case actions.SHOW_CHANNEL_UPDATE:
return Object.assign({}, state, {
showChannel: {
error : action.error,
channelData: action.channelData,
claimData : action.claimData,
error : action.data.error,
channelData: {
name : action.data.name,
shortId: action.data.shortId,
longId : action.data.longId,
},
claimData: action.data.claimData,
},
});
case actions.SHOW_CHANNEL_CLEAR:

View file

@ -97,27 +97,28 @@ function* newChannelRequest (action) {
if (!success) {
return yield put(addChannelRequest(id, message, null, null, null));
}
const { channelName, longChannelClaimId, shortChannelClaimId } = data;
yield put(addChannelRequest(id, null, channelName, longChannelClaimId, shortChannelClaimId));
const channelRecordId = `c#${channelName}#${longChannelClaimId}`; // move to the action
yield put(showNewChannel(channelRecordId, channelName, longChannelClaimId ));
const { longChannelClaimId: longId, shortChannelClaimId: shortId } = data;
yield put(addChannelRequest(id, null, name, longId, shortId));
const channelRecordId = `c#${name}#${longId}`; // move to the action
const channelData = {name, longId, shortId};
yield put(showNewChannel(channelRecordId, channelData));
}
function* getNewChannelDataAndShowChannel (action) {
const { id, name, longId, channelData } = action;
const { id, channelData: {name, shortId, longId} } = action.data;
let success, message, claimsData;
try {
({ success, message, data: claimsData } = yield call(getChannelClaims, name, longId, 1));
} catch (error) {
return yield put(updateShowChannel(error.message, channelData));
return yield put(updateShowChannel(error.message, name, shortId, longId));
// yield put(addNewChannelToChannelList(id, error.message, null, null));
}
if (!success) {
return yield put(updateShowChannel(message, channelData));
return yield put(updateShowChannel(message, name, shortId, longId));
// yield put(addNewChannelToChannelList(id, message, null, null));
}
yield put(updateShowChannel(null, channelData, claimsData));
yield put(addNewChannelToChannelList(id, null, channelData, claimsData));
yield put(updateShowChannel(null, name, shortId, longId, claimsData));
yield put(addNewChannelToChannelList(id, null, name, shortId, longId, claimsData));
}
export function* watchNewAssetRequest () {