From 764ce246764d24b3d98b5f0ea408dd1492281ae5 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 8 Feb 2018 14:01:45 -0800 Subject: [PATCH] moved asset and channel id out of saga to action --- react/actions/show.js | 6 +++-- react/containers/ShowAsset/index.js | 4 +-- react/containers/ShowAsset/view.jsx | 6 ++--- react/containers/ShowChannel/index.js | 4 +-- react/containers/ShowChannel/view.jsx | 8 +++--- react/sagas/show.js | 38 +++++++++------------------ 6 files changed, 26 insertions(+), 40 deletions(-) diff --git a/react/actions/show.js b/react/actions/show.js index f79f3627..4a1a125a 100644 --- a/react/actions/show.js +++ b/react/actions/show.js @@ -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 }, diff --git a/react/containers/ShowAsset/index.js b/react/containers/ShowAsset/index.js index e95d8c5e..6f5ce1b6 100644 --- a/react/containers/ShowAsset/index.js +++ b/react/containers/ShowAsset/index.js @@ -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)); diff --git a/react/containers/ShowAsset/view.jsx b/react/containers/ShowAsset/view.jsx index ae54de93..123ed807 100644 --- a/react/containers/ShowAsset/view.jsx +++ b/react/containers/ShowAsset/view.jsx @@ -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; diff --git a/react/containers/ShowChannel/index.js b/react/containers/ShowChannel/index.js index c2fda25a..32469e5f 100644 --- a/react/containers/ShowChannel/index.js +++ b/react/containers/ShowChannel/index.js @@ -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)); diff --git a/react/containers/ShowChannel/view.jsx b/react/containers/ShowChannel/view.jsx index 10643858..606f9cf8 100644 --- a/react/containers/ShowChannel/view.jsx +++ b/react/containers/ShowChannel/view.jsx @@ -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 () { diff --git a/react/sagas/show.js b/react/sagas/show.js index 20026ef3..5ea1cdc1 100644 --- a/react/sagas/show.js +++ b/react/sagas/show.js @@ -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));