debugged channel update reducer
This commit is contained in:
parent
0a3e052564
commit
967474bfa4
8 changed files with 37 additions and 42 deletions
|
@ -100,17 +100,17 @@ export function addChannelRequest (id, error, name, longId, shortId) {
|
||||||
|
|
||||||
// show a channel
|
// show a channel
|
||||||
|
|
||||||
export function showNewChannel (id, name, longId, channelData) {
|
export function showNewChannel (id, channelData) {
|
||||||
return {
|
return {
|
||||||
type: actions.SHOW_CHANNEL_NEW,
|
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 {
|
return {
|
||||||
type: actions.SHOW_CHANNEL_UPDATE,
|
type: actions.SHOW_CHANNEL_UPDATE,
|
||||||
data: { error, channelData, claimData },
|
data: { error, name, shortId, longId, claimData },
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,26 +2,15 @@ import Request from 'utils/request';
|
||||||
import request from '../utils/request';
|
import request from '../utils/request';
|
||||||
|
|
||||||
export function getChannelData (name, id) {
|
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';
|
if (!id) id = 'none';
|
||||||
const url = `/api/channel/data/${name}/${id}`;
|
const url = `/api/channel/data/${name}/${id}`;
|
||||||
return request(url);
|
return request(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getChannelClaims (name, longId, page) {
|
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;
|
if (!page) page = 1;
|
||||||
const url = `/api/channel/claims/${name}/${longId}/${page}`;
|
const url = `/api/channel/claims/${name}/${longId}/${page}`;
|
||||||
return Request(url);
|
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});
|
|
||||||
// });
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,7 +10,7 @@ const mapStateToProps = ({ show }) => {
|
||||||
requestModifier : show.request.data.modifier,
|
requestModifier : show.request.data.modifier,
|
||||||
requestExtension: show.request.data.extension,
|
requestExtension: show.request.data.extension,
|
||||||
assetRequests : show.assetRequests,
|
assetRequests : show.assetRequests,
|
||||||
assets : show.assets,
|
assetList : show.assetList,
|
||||||
// show asset
|
// show asset
|
||||||
error : show.showAsset.error,
|
error : show.showAsset.error,
|
||||||
name : show.showAsset.name,
|
name : show.showAsset.name,
|
||||||
|
|
|
@ -48,9 +48,9 @@ class ShowAsset extends React.Component {
|
||||||
return this.props.onRequestError(error);
|
return this.props.onRequestError(error);
|
||||||
}
|
}
|
||||||
// update the showAsset data in the store
|
// update the showAsset data in the store
|
||||||
const { assets } = this.props;
|
const { assetList } = this.props;
|
||||||
const assetId = `a#${name}#${claimId}`;
|
const assetId = `a#${name}#${claimId}`;
|
||||||
const existingAssetRecord = assets[assetId];
|
const existingAssetRecord = assetList[assetId];
|
||||||
if (existingAssetRecord) { // case: the asset data already exists
|
if (existingAssetRecord) { // case: the asset data already exists
|
||||||
this.showExistingAsset(existingAssetRecord);
|
this.showExistingAsset(existingAssetRecord);
|
||||||
} else { // case: the asset data does not exist yet
|
} else { // case: the asset data does not exist yet
|
||||||
|
|
|
@ -27,11 +27,11 @@ const mapDispatchToProps = dispatch => {
|
||||||
onRequestError: (error) => {
|
onRequestError: (error) => {
|
||||||
dispatch(updateRequestError(error, null, null));
|
dispatch(updateRequestError(error, null, null));
|
||||||
},
|
},
|
||||||
onShowNewChannel: (id, name, longId) => {
|
onShowNewChannel: (id, channelData) => {
|
||||||
dispatch(showNewChannel(id, name, longId));
|
dispatch(showNewChannel(id, channelData));
|
||||||
},
|
},
|
||||||
onShowExistingChannel: (error, channelData, claimData) => {
|
onShowExistingChannel: (error, name, shortId, longId, claimData) => {
|
||||||
dispatch(updateShowChannel(error, channelData, claimData));
|
dispatch(updateShowChannel(error, name, shortId, longId, claimData));
|
||||||
},
|
},
|
||||||
onShowChannelClear: () => {
|
onShowChannelClear: () => {
|
||||||
dispatch(clearShowChannel());
|
dispatch(clearShowChannel());
|
||||||
|
|
|
@ -49,17 +49,18 @@ class ShowChannel extends React.Component {
|
||||||
if (existingChannel) {
|
if (existingChannel) {
|
||||||
this.showExistingChannel(channelRecordId, existingChannel);
|
this.showExistingChannel(channelRecordId, existingChannel);
|
||||||
} else {
|
} else {
|
||||||
this.showNewChannel(channelRecordId, channelData.name, channelData.longId, channelData);
|
this.showNewChannel(channelRecordId, channelData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
showNewChannel (channelRecordId, name, longId) {
|
showNewChannel (channelRecordId, channelData) {
|
||||||
this.props.onShowNewChannel(channelRecordId, name, longId);
|
this.props.onShowNewChannel(channelRecordId, channelData);
|
||||||
};
|
};
|
||||||
showExistingChannel (existingChannel) {
|
showExistingChannel (existingChannel) {
|
||||||
const { error, channelData, claimData } = existingChannel;
|
const { error, channelData: {name, shortId, longId}, claimData } = existingChannel;
|
||||||
this.props.onShowExistingChannel(error, channelData, claimData);
|
this.props.onShowExistingChannel(error, name, shortId, longId, claimData);
|
||||||
};
|
};
|
||||||
componentWillUnmount () {
|
componentWillUnmount () {
|
||||||
|
console.log('ShowChannel will unmount');
|
||||||
this.props.onShowChannelClear();
|
this.props.onShowChannelClear();
|
||||||
}
|
}
|
||||||
render () {
|
render () {
|
||||||
|
|
|
@ -37,7 +37,7 @@ const initialState = {
|
||||||
channelRequests: {},
|
channelRequests: {},
|
||||||
channelList : {},
|
channelList : {},
|
||||||
assetRequests : {},
|
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:
|
case actions.SHOW_CHANNEL_UPDATE:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
showChannel: {
|
showChannel: {
|
||||||
error : action.error,
|
error : action.data.error,
|
||||||
channelData: action.channelData,
|
channelData: {
|
||||||
claimData : action.claimData,
|
name : action.data.name,
|
||||||
|
shortId: action.data.shortId,
|
||||||
|
longId : action.data.longId,
|
||||||
|
},
|
||||||
|
claimData: action.data.claimData,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
case actions.SHOW_CHANNEL_CLEAR:
|
case actions.SHOW_CHANNEL_CLEAR:
|
||||||
|
|
|
@ -97,27 +97,28 @@ function* newChannelRequest (action) {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
return yield put(addChannelRequest(id, message, null, null, null));
|
return yield put(addChannelRequest(id, message, null, null, null));
|
||||||
}
|
}
|
||||||
const { channelName, longChannelClaimId, shortChannelClaimId } = data;
|
const { longChannelClaimId: longId, shortChannelClaimId: shortId } = data;
|
||||||
yield put(addChannelRequest(id, null, channelName, longChannelClaimId, shortChannelClaimId));
|
yield put(addChannelRequest(id, null, name, longId, shortId));
|
||||||
const channelRecordId = `c#${channelName}#${longChannelClaimId}`; // move to the action
|
const channelRecordId = `c#${name}#${longId}`; // move to the action
|
||||||
yield put(showNewChannel(channelRecordId, channelName, longChannelClaimId ));
|
const channelData = {name, longId, shortId};
|
||||||
|
yield put(showNewChannel(channelRecordId, channelData));
|
||||||
}
|
}
|
||||||
|
|
||||||
function* getNewChannelDataAndShowChannel (action) {
|
function* getNewChannelDataAndShowChannel (action) {
|
||||||
const { id, name, longId, channelData } = action;
|
const { id, channelData: {name, shortId, longId} } = action.data;
|
||||||
let success, message, claimsData;
|
let success, message, claimsData;
|
||||||
try {
|
try {
|
||||||
({ success, message, data: claimsData } = yield call(getChannelClaims, name, longId, 1));
|
({ success, message, data: claimsData } = yield call(getChannelClaims, name, longId, 1));
|
||||||
} catch (error) {
|
} 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));
|
// yield put(addNewChannelToChannelList(id, error.message, null, null));
|
||||||
}
|
}
|
||||||
if (!success) {
|
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(addNewChannelToChannelList(id, message, null, null));
|
||||||
}
|
}
|
||||||
yield put(updateShowChannel(null, channelData, claimsData));
|
yield put(updateShowChannel(null, name, shortId, longId, claimsData));
|
||||||
yield put(addNewChannelToChannelList(id, null, channelData, claimsData));
|
yield put(addNewChannelToChannelList(id, null, name, shortId, longId, claimsData));
|
||||||
}
|
}
|
||||||
|
|
||||||
export function* watchNewAssetRequest () {
|
export function* watchNewAssetRequest () {
|
||||||
|
|
Loading…
Reference in a new issue