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

View file

@ -27,8 +27,8 @@ const mapDispatchToProps = dispatch => {
onRequestError: (error) => {
dispatch(updateRequestError(error, null, null));
},
onShowNewAsset: (id, name, claimId) => {
dispatch(showNewAsset(id, name, claimId));
onShowNewAsset: (name, claimId) => {
dispatch(showNewAsset(name, claimId));
},
onShowExistingAsset: (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
this.showExistingAsset(existingAssetRecord);
} else { // case: the asset data does not exist yet
this.showNewAsset(assetId, name, claimId);
this.showNewAsset(name, claimId);
}
}
showNewAsset (assetId, name, claimId) {
this.props.onShowNewAsset(assetId, name, claimId);
showNewAsset (name, claimId) {
this.props.onShowNewAsset(name, claimId);
}
showExistingAsset (existingAssetRecord) {
let { error, name, claimId, shortId, claimData } = existingAssetRecord;

View file

@ -27,8 +27,8 @@ const mapDispatchToProps = dispatch => {
onRequestError: (error) => {
dispatch(updateRequestError(error, null, null));
},
onShowNewChannel: (id, channelData) => {
dispatch(showNewChannel(id, channelData));
onShowNewChannel: (channelData) => {
dispatch(showNewChannel(channelData));
},
onShowExistingChannel: (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) {
this.showExistingChannel(existingChannel);
} else {
this.showNewChannel(channelRecordId, channelData);
this.showNewChannel(channelData);
}
}
showNewChannel (channelRecordId, channelData) {
this.props.onShowNewChannel(channelRecordId, channelData);
showNewChannel (channelData) {
this.props.onShowNewChannel(channelData);
};
showExistingChannel (existingChannel) {
console.log('showExistingChannel:', existingChannel);
const { error, channelData: {name, shortId, longId}, claimsData } = existingChannel;
this.props.onShowExistingChannel(error, name, shortId, longId, claimsData);
};
componentWillUnmount () {
console.log('ShowChannel will unmount');
this.props.onShowChannelClear();
}
render () {

View file

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