From 855a7dab42aa66b408cfe543561d3a79c88e70a7 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Tue, 13 Feb 2018 15:53:27 -0800 Subject: [PATCH] removed showAsset action --- react/actions/show.js | 18 +++----------- react/api/assetApi.js | 6 ++--- react/constants/show_action_types.js | 2 +- react/containers/ShowAsset/index.js | 12 +++------ react/containers/ShowAsset/view.jsx | 16 +++--------- react/sagas/index.js | 2 -- react/sagas/request.js | 37 ++++++++++++++++++++++------ react/sagas/show_asset.js | 30 ---------------------- 8 files changed, 44 insertions(+), 79 deletions(-) delete mode 100644 react/sagas/show_asset.js diff --git a/react/actions/show.js b/react/actions/show.js index 0b162b25..f3244e8e 100644 --- a/react/actions/show.js +++ b/react/actions/show.js @@ -39,30 +39,18 @@ export function updateRequestWithAssetRequest (name, id, channelName, channelId, export function newAssetRequest (id, name, modifier) { return { - type: actions.ASSET_REQUEST_ASYNC, + type: actions.ASSET_REQUEST_NEW, data: { id, name, modifier }, }; }; -export function addAssetRequest (id, error, name, claimId) { +export function addRequestToAssetRequests (id, error, name, claimId) { return { type: actions.ASSET_REQUEST_SUCCESS, data: { id, error, name, claimId }, }; }; -// show an asset - -export function showNewAsset (name, claimId) { - const id = `a#${name}#${claimId}`; - return { - type: actions.ASSET_NEW_ASYNC, - data: { id, name, claimId }, - }; -}; - -// add asset to asset list - export function addAssetToAssetList (id, error, name, claimId, shortId, claimData) { return { type: actions.ASSET_NEW_SUCCESS, @@ -79,7 +67,7 @@ export function newChannelRequest (id, name, channelId) { }; }; -export function addChannelRequest (id, error, name, longId, shortId) { +export function addRequestToChannelRequests (id, error, name, longId, shortId) { return { type: actions.CHANNEL_REQUEST_SUCCESS, data: { id, error, name, longId, shortId }, diff --git a/react/api/assetApi.js b/react/api/assetApi.js index a53dd136..6664a493 100644 --- a/react/api/assetApi.js +++ b/react/api/assetApi.js @@ -1,7 +1,7 @@ import Request from 'utils/request'; export function getLongClaimId (name, modifier) { - console.log('getting long claim id for asset:', name, modifier); + // console.log('getting long claim id for asset:', name, modifier); let body = {}; // create request params if (modifier) { @@ -27,13 +27,13 @@ export function getLongClaimId (name, modifier) { }; export function getShortId (name, claimId) { - console.log('getting short id for asset:', name, claimId); + // console.log('getting short id for asset:', name, claimId); const url = `/api/claim/short-id/${claimId}/${name}`; return Request(url); }; export function getClaimData (name, claimId) { - console.log('getting claim data for asset:', name, claimId); + // console.log('getting claim data for asset:', name, claimId); const url = `/api/claim/data/${name}/${claimId}`; return Request(url); }; diff --git a/react/constants/show_action_types.js b/react/constants/show_action_types.js index 4fbf942f..169a1342 100644 --- a/react/constants/show_action_types.js +++ b/react/constants/show_action_types.js @@ -4,7 +4,7 @@ export const REQUEST_UPDATE_CLAIM = 'REQUEST_UPDATE_CLAIM'; export const REQUEST_ERROR = 'REQUEST_ERROR'; // asset actions -export const ASSET_REQUEST_ASYNC = 'ASSET_REQUEST_ASYNC'; +export const ASSET_REQUEST_NEW = 'ASSET_REQUEST_NEW'; export const ASSET_REQUEST_SUCCESS = 'ASSET_REQUEST_SUCCESS'; export const ASSET_NEW_ASYNC = 'ASSET_NEW_ASYNC'; diff --git a/react/containers/ShowAsset/index.js b/react/containers/ShowAsset/index.js index a2cd09a4..43b0ca14 100644 --- a/react/containers/ShowAsset/index.js +++ b/react/containers/ShowAsset/index.js @@ -9,14 +9,15 @@ const mapStateToProps = ({ show }) => { const requestName = show.request.data.name; const requestModifier = show.request.data.modifier; const requestExtension = show.request.data.extension; - // select request - const previousRequest = show.assetRequests[show.request.id] || null; + const assetList = show.assetList; // select asset info + const previousRequest = show.assetRequests[show.request.id] || null; let asset; if (previousRequest) { const assetKey = `a#${previousRequest.name}#${previousRequest.claimId}`; // note: just store this in the request - asset = show.assetList[assetKey] || null; + asset = assetList[assetKey] || null; }; + // console.log('previousRequest:', previousRequest, 'asset:', asset, 'asset list', assetList); // return props return { requestType, @@ -24,7 +25,6 @@ const mapStateToProps = ({ show }) => { requestName, requestModifier, requestExtension, - previousRequest, asset, }; }; @@ -35,10 +35,6 @@ const mapDispatchToProps = dispatch => { onNewRequest: (id, name, modifier) => { dispatch(newAssetRequest(id, name, modifier)); }, - // show asset - onShowNewAsset: (name, claimId) => { - dispatch(showNewAsset(name, claimId)); - }, }; }; diff --git a/react/containers/ShowAsset/view.jsx b/react/containers/ShowAsset/view.jsx index 6cf7cfb9..fad53ee1 100644 --- a/react/containers/ShowAsset/view.jsx +++ b/react/containers/ShowAsset/view.jsx @@ -11,25 +11,17 @@ function requestIsAnAssetRequest ({ requestType }) { class ShowAsset extends React.Component { componentDidMount () { - const { asset, previousRequest, requestId, requestName, requestModifier } = this.props; - if (!previousRequest) { // case: the asset request does not exist + const { asset, requestId, requestName, requestModifier } = this.props; + if (!asset) { // case: the asset info does not exist return this.props.onNewRequest(requestId, requestName, requestModifier); }; - if (!asset) { // case: the asset request does not exist - const { name, claimId } = previousRequest; - return this.props.onShowNewAsset(name, claimId); - }; } componentWillReceiveProps (nextProps) { if (requestIsAnAssetRequest(nextProps)) { - const { asset, previousRequest, requestId, requestName, requestModifier } = nextProps; - if (!previousRequest) { + const { asset, requestId, requestName, requestModifier } = nextProps; + if (!asset) { // case: the asset info does not exist return this.props.onNewRequest(requestId, requestName, requestModifier); }; - if (!asset) { - const { name, claimId } = previousRequest; - return this.props.onShowNewAsset(name, claimId); - }; } } render () { diff --git a/react/sagas/index.js b/react/sagas/index.js index 79935b0f..0c5341a9 100644 --- a/react/sagas/index.js +++ b/react/sagas/index.js @@ -2,13 +2,11 @@ import { all } from 'redux-saga/effects'; import { watchNewAssetRequest, watchNewChannelRequest } from './request'; import { watchFileIsRequested } from './file'; import { watchShowNewChannel, watchShowNewChannelClaimsRequest } from './show_channel'; -import { watchShowNewAsset } from './show_asset'; export default function* rootSaga () { yield all([ watchNewAssetRequest(), watchNewChannelRequest(), - watchShowNewAsset(), watchShowNewChannel(), watchFileIsRequested(), watchShowNewChannelClaimsRequest(), diff --git a/react/sagas/request.js b/react/sagas/request.js index 4b87b454..ab5212a8 100644 --- a/react/sagas/request.js +++ b/react/sagas/request.js @@ -1,12 +1,13 @@ import { call, put, takeLatest } from 'redux-saga/effects'; import * as actions from 'constants/show_action_types'; -import { addAssetRequest, updateRequestError, showNewAsset, addChannelRequest, showNewChannel } from 'actions/show'; -import { getLongClaimId } from 'api/assetApi'; +import { addRequestToAssetRequests, updateRequestError, addRequestToChannelRequests, showNewChannel, addAssetToAssetList } from 'actions/show'; +import { getLongClaimId, getShortId, getClaimData } from 'api/assetApi'; import { getChannelData } from 'api/channelApi'; function* newAssetRequest (action) { const { id, name, modifier } = action.data; - console.log('getting asset long id'); + // get long id + console.log(`getting asset long id ${name}`); let longId; try { ({data: longId} = yield call(getLongClaimId, name, modifier)); @@ -14,8 +15,29 @@ function* newAssetRequest (action) { console.log('error:', error); return yield put(updateRequestError(error.message)); } - yield put(addAssetRequest(id, null, name, longId)); - yield put(showNewAsset(name, longId)); + // put action to add request to asset request list + yield put(addRequestToAssetRequests(id, null, name, longId)); + // get short Id + console.log(`getting asset short id ${name} ${longId}`); + let shortId; + try { + ({data: shortId} = yield call(getShortId, name, longId)); + } catch (error) { + return yield put(updateRequestError(error.message)); + } + // get claim data + console.log(`getting asset claim data ${name} ${longId}`); + let claimData; + try { + ({data: claimData} = yield call(getClaimData, name, longId)); + } catch (error) { + return yield put(updateRequestError(error.message)); + } + // put action to add asset to asset list + const assetKey = `a#${name}#${longId}`; + yield put(addAssetToAssetList(assetKey, null, name, longId, shortId, claimData)); + // clear any errors in request error + yield put(updateRequestError(null)); }; function* newChannelRequest (action) { @@ -25,16 +47,15 @@ function* newChannelRequest (action) { try { ({data} = yield call(getChannelData, name, channelId)); } catch (error) { - // return yield put(addChannelRequest(id, error.message, null, null, null)); return yield put(updateRequestError(error.message)); } const { longChannelClaimId: longId, shortChannelClaimId: shortId } = data; - yield put(addChannelRequest(id, null, name, longId, shortId)); + yield put(addRequestToChannelRequests(id, null, name, longId, shortId)); yield put(showNewChannel(name, shortId, longId)); } export function* watchNewAssetRequest () { - yield takeLatest(actions.ASSET_REQUEST_ASYNC, newAssetRequest); + yield takeLatest(actions.ASSET_REQUEST_NEW, newAssetRequest); }; export function* watchNewChannelRequest () { diff --git a/react/sagas/show_asset.js b/react/sagas/show_asset.js deleted file mode 100644 index 8f9200b8..00000000 --- a/react/sagas/show_asset.js +++ /dev/null @@ -1,30 +0,0 @@ -import { call, put, takeLatest } from 'redux-saga/effects'; -import * as actions from 'constants/show_action_types'; -import { updateRequestError, addAssetToAssetList } from 'actions/show'; -import { getShortId, getClaimData } from 'api/assetApi'; - -function* getAssetDataAndShowAsset (action) { - const {id, name, claimId} = action.data; - // get short Id - console.log('getting short id'); - let shortId; - try { - ({data: shortId} = yield call(getShortId, name, claimId)); - } catch (error) { - return yield put(updateRequestError(error.message)); - } - // if no error, get claim data - console.log('getting claim data'); - let claimData; - try { - ({data: claimData} = yield call(getClaimData, name, claimId)); - } catch (error) { - return yield put(updateRequestError(error.message)); - } - yield put(addAssetToAssetList(id, null, name, claimId, shortId, claimData)); - yield put(updateRequestError(null)); -} - -export function* watchShowNewAsset () { - yield takeLatest(actions.ASSET_NEW_ASYNC, getAssetDataAndShowAsset); -};