From 0cecc84dde0a91a0e15d3cbfe417b5fdfbb273d5 Mon Sep 17 00:00:00 2001
From: bill bittner <bittner.w@gmail.com>
Date: Wed, 14 Feb 2018 12:09:57 -0800
Subject: [PATCH] consolidated requests into one list

---
 react/actions/show.js                         | 29 ++++++++++------
 react/components/AssetDisplay/index.js        |  4 +--
 react/components/AssetInfo/index.js           |  4 +--
 react/components/AssetTitle/index.js          |  4 +--
 react/components/ShowAssetDetails/index.js    |  6 ++--
 react/components/ShowAssetLite/index.js       |  7 ++--
 react/components/ShowChannel/index.js         |  4 +--
 react/constants/show_action_types.js          |  2 +-
 .../containers/ChannelClaimsDisplay/index.js  |  4 +--
 react/reducers/show.js                        | 34 ++++++-------------
 react/sagas/show_asset.js                     |  6 ++--
 react/sagas/show_channel.js                   |  6 ++--
 12 files changed, 52 insertions(+), 58 deletions(-)

diff --git a/react/actions/show.js b/react/actions/show.js
index cae8c4e3..ae67e44b 100644
--- a/react/actions/show.js
+++ b/react/actions/show.js
@@ -39,15 +39,22 @@ export function onNewAssetRequest (name, id, channelName, channelId, extension)
   };
 };
 
-// asset actions
-
-export function addRequestToAssetRequests (id, error, name, claimId) {
+export function addRequestToPreviousRequests (id, error, key) {
   return {
-    type: actions.ASSET_REQUEST_SUCCESS,
-    data: { id, error, name, claimId },
+    type: actions.PREVIOUS_REQUEST_ADD,
+    data: { id, error, key },
   };
 };
 
+// asset actions
+
+// export function addRequestToAssetRequests (id, error, name, claimId) {
+//   return {
+//     type: actions.ASSET_REQUEST_ADD,
+//     data: { id, error, name, claimId },
+//   };
+// };
+
 export function addAssetToAssetList (id, error, name, claimId, shortId, claimData) {
   return {
     type: actions.ASSET_ADD,
@@ -57,12 +64,12 @@ export function addAssetToAssetList (id, error, name, claimId, shortId, claimDat
 
 // channel actions
 
-export function addRequestToChannelRequests (id, error, name, longId, shortId) {
-  return {
-    type: actions.CHANNEL_REQUEST_ADD,
-    data: { id, error, name, longId, shortId },
-  };
-};
+// export function addRequestToChannelRequests (id, error, name, longId, shortId) {
+//   return {
+//     type: actions.CHANNEL_REQUEST_ADD,
+//     data: { id, error, name, longId, shortId },
+//   };
+// };
 
 export function addNewChannelToChannelList (id, name, shortId, longId, claimsData) {
   return {
diff --git a/react/components/AssetDisplay/index.js b/react/components/AssetDisplay/index.js
index be3b5975..37e09c71 100644
--- a/react/components/AssetDisplay/index.js
+++ b/react/components/AssetDisplay/index.js
@@ -7,8 +7,8 @@ const mapStateToProps = ({ show }) => {
   const error  = show.displayAsset.error;
   const status = show.displayAsset.status;
   // select asset
-  const request = show.assetRequests[show.request.id];
-  const assetKey = `a#${request.name}#${request.claimId}`;
+  const request = show.previousRequests[show.request.id];
+  const assetKey = request.key;
   const asset = show.assetList[assetKey];
   //  return props
   return {
diff --git a/react/components/AssetInfo/index.js b/react/components/AssetInfo/index.js
index f571574a..712dc75c 100644
--- a/react/components/AssetInfo/index.js
+++ b/react/components/AssetInfo/index.js
@@ -3,8 +3,8 @@ import View from './view';
 
 const mapStateToProps = ({ show }) => {
   // select asset
-  const request = show.assetRequests[show.request.id];
-  const assetKey = `a#${request.name}#${request.claimId}`;
+  const request = show.previousRequests[show.request.id];
+  const assetKey = request.key;
   const asset = show.assetList[assetKey];
   //  return props
   return {
diff --git a/react/components/AssetTitle/index.js b/react/components/AssetTitle/index.js
index ff3b9792..ea6b9a7b 100644
--- a/react/components/AssetTitle/index.js
+++ b/react/components/AssetTitle/index.js
@@ -3,8 +3,8 @@ import View from './view';
 
 const mapStateToProps = ({ show }) => {
   // select title
-  const request = show.assetRequests[show.request.id];
-  const assetKey = `a#${request.name}#${request.claimId}`;
+  const request = show.previousRequests[show.request.id];
+  const assetKey = request.key;
   const asset = show.assetList[assetKey];
   let title;
   if (asset) {
diff --git a/react/components/ShowAssetDetails/index.js b/react/components/ShowAssetDetails/index.js
index d8061a34..d50108f5 100644
--- a/react/components/ShowAssetDetails/index.js
+++ b/react/components/ShowAssetDetails/index.js
@@ -7,10 +7,10 @@ const mapStateToProps = ({ show }) => {
   const requestId = show.request.id;
   // select asset info
   let asset;
-  const previousRequest = show.assetRequests[requestId] || null;
+  const request = show.previousRequests[requestId] || null;
   const assetList = show.assetList;
-  if (previousRequest) {
-    const assetKey = `a#${previousRequest.name}#${previousRequest.claimId}`;  // note: just store this in the request
+  if (request && assetList) {
+    const assetKey = request.key;  // note: just store this in the request
     asset = assetList[assetKey] || null;
   };
   // return props
diff --git a/react/components/ShowAssetLite/index.js b/react/components/ShowAssetLite/index.js
index 40c09afd..d50108f5 100644
--- a/react/components/ShowAssetLite/index.js
+++ b/react/components/ShowAssetLite/index.js
@@ -7,11 +7,10 @@ const mapStateToProps = ({ show }) => {
   const requestId = show.request.id;
   // select asset info
   let asset;
-  const previousRequest = show.assetRequests[requestId] || null;
-  console.log('previous request:', previousRequest);
+  const request = show.previousRequests[requestId] || null;
   const assetList = show.assetList;
-  if (previousRequest) {
-    const assetKey = `a#${previousRequest.name}#${previousRequest.claimId}`;  // note: just store this in the request
+  if (request && assetList) {
+    const assetKey = request.key;  // note: just store this in the request
     asset = assetList[assetKey] || null;
   };
   // return props
diff --git a/react/components/ShowChannel/index.js b/react/components/ShowChannel/index.js
index 8de0944f..7c4fb492 100644
--- a/react/components/ShowChannel/index.js
+++ b/react/components/ShowChannel/index.js
@@ -5,11 +5,11 @@ const mapStateToProps = ({ show }) => {
   // select request info
   const requestId = show.request.id;
   // select request
-  const previousRequest = show.channelRequests[requestId] || null;
+  const previousRequest = show.previousRequests[requestId] || null;
   // select channel
   let channel;
   if (previousRequest) {
-    const channelKey = `c#${previousRequest.name}#${previousRequest.longId}`;
+    const channelKey = previousRequest.key;
     channel = show.channelList[channelKey] || null;
   }
   return {
diff --git a/react/constants/show_action_types.js b/react/constants/show_action_types.js
index 9927408e..7abb46f6 100644
--- a/react/constants/show_action_types.js
+++ b/react/constants/show_action_types.js
@@ -4,7 +4,7 @@ export const ASSET_REQUEST_NEW = 'ASSET_REQUEST_NEW';
 export const CHANNEL_REQUEST_NEW = 'CHANNEL_REQUEST_NEW';
 
 // asset actions
-export const ASSET_REQUEST_SUCCESS = 'ASSET_REQUEST_SUCCESS';
+export const PREVIOUS_REQUEST_ADD = 'PREVIOUS_REQUEST_ADD';
 export const ASSET_ADD = `ASSET_ADD`;
 
 // channel actions
diff --git a/react/containers/ChannelClaimsDisplay/index.js b/react/containers/ChannelClaimsDisplay/index.js
index 0fd7b165..46a130dc 100644
--- a/react/containers/ChannelClaimsDisplay/index.js
+++ b/react/containers/ChannelClaimsDisplay/index.js
@@ -4,8 +4,8 @@ import View from './view';
 
 const mapStateToProps = ({ show }) => {
   // select channel key
-  const request = show.channelRequests[show.request.id];
-  const channelKey = `c#${request.name}#${request.longId}`;
+  const request = show.previousRequests[show.request.id];
+  const channelKey = request.key;
   // select channel claims
   const channel = show.channelList[channelKey] || null;
   // return props
diff --git a/react/reducers/show.js b/react/reducers/show.js
index 699540ec..4eeac66e 100644
--- a/react/reducers/show.js
+++ b/react/reducers/show.js
@@ -7,11 +7,10 @@ const initialState = {
     type : null,
     id   : null,
   },
-  channelRequests: {},
-  channelList    : {},
-  assetRequests  : {},
-  assetList      : {},
-  displayAsset   : {
+  previousRequests: {},
+  channelList     : {},
+  assetList       : {},
+  displayAsset    : {
     error : null,
     status: LOCAL_CHECK,
   },
@@ -34,17 +33,17 @@ export default function (state = initialState, action) {
           id  : action.data.requestId,
         }),
       });
-    // asset actions
-    case actions.ASSET_REQUEST_SUCCESS:
+    // store requests
+    case actions.PREVIOUS_REQUEST_ADD:
       return Object.assign({}, state, {
-        assetRequests: Object.assign({}, state.assetRequests, {
+        previousRequests: Object.assign({}, state.previousRequests, {
           [action.data.id]: {
-            error  : action.data.error,
-            name   : action.data.name,
-            claimId: action.data.claimId,
+            error: action.data.error,
+            key  : action.data.key,
           },
         }),
       });
+    // asset data
     case actions.ASSET_ADD:
       return Object.assign({}, state, {
         assetList: Object.assign({}, state.assetList, {
@@ -57,18 +56,7 @@ export default function (state = initialState, action) {
           },
         }),
       });
-    // channel actions
-    case actions.CHANNEL_REQUEST_ADD:
-      return Object.assign({}, state, {
-        channelRequests: Object.assign({}, state.channelRequests, {
-          [action.data.id]: {
-            error  : action.data.error,
-            name   : action.data.name,
-            longId : action.data.longId,
-            shortId: action.data.shortId,
-          },
-        }),
-      });
+    // channel data
     case actions.CHANNEL_ADD:
       return Object.assign({}, state, {
         channelList: Object.assign({}, state.channelList, {
diff --git a/react/sagas/show_asset.js b/react/sagas/show_asset.js
index 6f21b0ec..37aca36e 100644
--- a/react/sagas/show_asset.js
+++ b/react/sagas/show_asset.js
@@ -1,6 +1,6 @@
 import { call, put, takeLatest } from 'redux-saga/effects';
 import * as actions from 'constants/show_action_types';
-import { addRequestToAssetRequests, onRequestError, addAssetToAssetList } from 'actions/show';
+import { addRequestToPreviousRequests, onRequestError, addAssetToAssetList } from 'actions/show';
 import { getLongClaimId, getShortId, getClaimData } from 'api/assetApi';
 
 function* newAssetRequest (action) {
@@ -15,7 +15,8 @@ function* newAssetRequest (action) {
     return yield put(onRequestError(error.message));
   }
   // put action to add request to asset request list
-  yield put(addRequestToAssetRequests(requestId, null, name, longId));
+  const assetKey = `a#${name}#${longId}`;
+  yield put(addRequestToPreviousRequests(requestId, null, assetKey));
   // get short Id
   console.log(`getting asset short id ${name} ${longId}`);
   let shortId;
@@ -33,7 +34,6 @@ function* newAssetRequest (action) {
     return yield put(onRequestError(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(onRequestError(null));
diff --git a/react/sagas/show_channel.js b/react/sagas/show_channel.js
index 981d6cc7..864a4b85 100644
--- a/react/sagas/show_channel.js
+++ b/react/sagas/show_channel.js
@@ -1,6 +1,6 @@
 import { call, put, takeLatest } from 'redux-saga/effects';
 import * as actions from 'constants/show_action_types';
-import { addNewChannelToChannelList, addRequestToChannelRequests, onRequestError, updateChannelClaims } from 'actions/show';
+import { addNewChannelToChannelList, addRequestToPreviousRequests, onRequestError, updateChannelClaims } from 'actions/show';
 import { getChannelClaims, getChannelData } from 'api/channelApi';
 
 function* getNewChannelAndUpdateChannelList (action) {
@@ -14,7 +14,8 @@ function* getNewChannelAndUpdateChannelList (action) {
     return yield put(onRequestError(error.message));
   }
   // store the request in the channel requests list
-  yield put(addRequestToChannelRequests(requestId, null, channelName, longId, shortId));
+  const channelKey = `c#${channelName}#${longId}`;
+  yield put(addRequestToPreviousRequests(requestId, null, channelKey));
   // get channel claims data
   console.log('getting channel claims data');
   let claimsData;
@@ -24,7 +25,6 @@ function* getNewChannelAndUpdateChannelList (action) {
     return yield put(onRequestError(error.message));
   }
   // store the channel data in the channel list
-  const channelKey = `c#${channelName}#${longId}`;
   yield put(addNewChannelToChannelList(channelKey, channelName, shortId, longId, claimsData));
   // clear any request errors
   yield put(onRequestError(null));