moved asset and channel id out of saga to action

This commit is contained in:
bill bittner 2018-02-08 14:01:45 -08:00
parent eb2f7ac7fc
commit 764ce24676
6 changed files with 26 additions and 40 deletions

View file

@ -53,7 +53,8 @@ export function addAssetRequest (id, error, name, claimId) {
// show an asset // show an asset
export function showNewAsset (id, name, claimId) { export function showNewAsset (name, claimId) {
const id = `a#${name}#${claimId}`;
return { return {
type: actions.SHOW_ASSET_NEW, type: actions.SHOW_ASSET_NEW,
data: { id, name, claimId }, data: { id, name, claimId },
@ -100,7 +101,8 @@ export function addChannelRequest (id, error, name, longId, shortId) {
// show a channel // show a channel
export function showNewChannel (id, channelData) { export function showNewChannel (channelData) {
const id = `c#${channelData.name}#${channelData.longId}`; // move to the action
return { return {
type: actions.SHOW_CHANNEL_NEW, type: actions.SHOW_CHANNEL_NEW,
data: { id, channelData }, data: { id, channelData },

View file

@ -27,8 +27,8 @@ const mapDispatchToProps = dispatch => {
onRequestError: (error) => { onRequestError: (error) => {
dispatch(updateRequestError(error, null, null)); dispatch(updateRequestError(error, null, null));
}, },
onShowNewAsset: (id, name, claimId) => { onShowNewAsset: (name, claimId) => {
dispatch(showNewAsset(id, name, claimId)); dispatch(showNewAsset(name, claimId));
}, },
onShowExistingAsset: (error, name, claimId, shortId, claimData) => { onShowExistingAsset: (error, name, claimId, shortId, claimData) => {
dispatch(updateShowAsset(error, name, claimId, shortId, claimData)); dispatch(updateShowAsset(error, name, claimId, shortId, claimData));

View file

@ -54,11 +54,11 @@ class ShowAsset extends React.Component {
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
this.showNewAsset(assetId, name, claimId); this.showNewAsset(name, claimId);
} }
} }
showNewAsset (assetId, name, claimId) { showNewAsset (name, claimId) {
this.props.onShowNewAsset(assetId, name, claimId); this.props.onShowNewAsset(name, claimId);
} }
showExistingAsset (existingAssetRecord) { showExistingAsset (existingAssetRecord) {
let { error, name, claimId, shortId, claimData } = existingAssetRecord; let { error, name, claimId, shortId, claimData } = existingAssetRecord;

View file

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

View file

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

View file

@ -12,30 +12,25 @@ function* newAssetRequest (action) {
try { try {
({success, message, data: longId} = yield call(getLongClaimId, name, modifier)); ({success, message, data: longId} = yield call(getLongClaimId, name, modifier));
} catch (error) { } catch (error) {
// yield put(addAssetRequest(id, error.message, name, null));
return yield put(updateRequestError(error.message)); return yield put(updateRequestError(error.message));
} }
if (!success) { if (!success) {
// yield put(addAssetRequest(id, message, name, null));
return yield put(updateRequestError(message)); return yield put(updateRequestError(message));
} }
yield put(addAssetRequest(id, null, name, longId)); yield put(addAssetRequest(id, null, name, longId));
const newAssetId = `a#${name}#${longId}`; // note: move to action yield put(showNewAsset(name, longId));
yield put(showNewAsset(newAssetId, name, longId));
}; };
function* getAssetDataAndShowAsset (action) { function* getAssetDataAndShowAsset (action) {
const {id, name, claimId} = action.data; const {id, name, claimId} = action.data;
// if no error, get short Id // get short Id
let success, message, shortId; let success, message, shortId;
try { try {
({success, message, data: shortId} = yield call(getShortId, name, claimId)); ({success, message, data: shortId} = yield call(getShortId, name, claimId));
} catch (error) { } catch (error) {
// yield put(addAssetToAssetList());
return yield put(updateShowAsset(error.message, name, claimId)); return yield put(updateShowAsset(error.message, name, claimId));
} }
if (!success) { if (!success) {
// yield put(addAssetToAssetList());
return yield put(updateShowAsset(message, name, claimId)); return yield put(updateShowAsset(message, name, claimId));
} }
// if no error, get claim data // if no error, get claim data
@ -44,14 +39,11 @@ function* getAssetDataAndShowAsset (action) {
try { try {
({success, message, data: claimData} = yield call(getClaimData, name, claimId)); ({success, message, data: claimData} = yield call(getClaimData, name, claimId));
} catch (error) { } catch (error) {
// yield put(addAssetToAssetList());
return yield put(updateShowAsset(error.message, name, claimId)); return yield put(updateShowAsset(error.message, name, claimId));
} }
if (!success) { if (!success) {
// yield put(addAssetToAssetList());
return yield put(updateShowAsset(message, name, claimId)); return yield put(updateShowAsset(message, name, claimId));
} }
// if both are successfull, add to asset list and select for showing
yield put(updateShowAsset(null, name, claimId, shortId, claimData)); yield put(updateShowAsset(null, name, claimId, shortId, claimData));
yield put(addAssetToAssetList(id, null, name, claimId, shortId, claimData)); yield put(addAssetToAssetList(id, null, name, claimId, shortId, claimData));
} }
@ -66,26 +58,23 @@ function* retrieveFile (action) {
} catch (error) { } catch (error) {
return yield put(updateDisplayAssetError(error.message)); return yield put(updateDisplayAssetError(error.message));
}; };
if (success) { if (!success) {
return yield put(updateDisplayAssetError(message));
}
if (isAvailable) { if (isAvailable) {
return yield put(updateFileAvailability(AVAILABLE)); return yield put(updateFileAvailability(AVAILABLE));
} }
yield put(updateFileAvailability(UNAVAILABLE)); yield put(updateFileAvailability(UNAVAILABLE));
} else {
yield put(updateDisplayAssetError(message));
}
// initiate get request for the file // initiate get request for the file
try { try {
({ success, message } = yield call(triggerClaimGet, name, claimId)); ({ success, message } = yield call(triggerClaimGet, name, claimId));
} catch (error) { } catch (error) {
return yield put(updateDisplayAssetError(error.message)); return yield put(updateDisplayAssetError(error.message));
}; };
if (success) { if (!success) {
console.log('/api/glaim-get response:', message); return yield put(updateDisplayAssetError(message));
yield put(updateFileAvailability(AVAILABLE));
} else {
yield put(updateDisplayAssetError(message));
} }
yield put(updateFileAvailability(AVAILABLE));
}; };
function* newChannelRequest (action) { function* newChannelRequest (action) {
@ -103,9 +92,8 @@ function* newChannelRequest (action) {
} }
const { longChannelClaimId: longId, shortChannelClaimId: shortId } = data; const { longChannelClaimId: longId, shortChannelClaimId: shortId } = data;
yield put(addChannelRequest(id, null, name, longId, shortId)); yield put(addChannelRequest(id, null, name, longId, shortId));
const channelRecordId = `c#${name}#${longId}`; // move to the action
const channelData = {name, longId, shortId}; const channelData = {name, longId, shortId};
yield put(showNewChannel(channelRecordId, channelData)); yield put(showNewChannel(channelData));
} }
function* getNewChannelDataAndShowChannel (action) { function* getNewChannelDataAndShowChannel (action) {
@ -114,11 +102,9 @@ function* getNewChannelDataAndShowChannel (action) {
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) {
// yield put(addNewChannelToChannelList(id, error.message, null, null));
return yield put(updateShowChannel(error.message, name, shortId, longId)); return yield put(updateShowChannel(error.message, name, shortId, longId));
} }
if (!success) { if (!success) {
// yield put(addNewChannelToChannelList(id, message, null, null));
return yield put(updateShowChannel(message, name, shortId, longId)); return yield put(updateShowChannel(message, name, shortId, longId));
} }
yield put(updateShowChannel(null, name, shortId, longId, claimsData)); yield put(updateShowChannel(null, name, shortId, longId, claimsData));