From 249b6c6f0f1b68204009826f5689fb885ea6462d Mon Sep 17 00:00:00 2001 From: bill bittner Date: Mon, 12 Feb 2018 18:18:56 -0800 Subject: [PATCH] moved channel selection logic to mapStateToProps --- react/actions/show.js | 48 +++------- react/components/AssetDisplay/index.js | 15 ++- react/components/AssetInfo/index.js | 10 +- react/components/AssetTitle/index.js | 10 +- react/components/ShowAssetDetails/index.js | 8 +- react/components/ShowAssetDetails/view.jsx | 7 -- react/components/ShowAssetLite/index.js | 11 ++- react/components/ShowAssetLite/view.jsx | 2 +- react/constants/show_action_types.js | 5 +- .../containers/ChannelClaimsDisplay/index.js | 17 +++- .../containers/ChannelClaimsDisplay/view.jsx | 53 +++++------ react/containers/ShowAsset/index.js | 40 ++++---- react/containers/ShowAsset/view.jsx | 91 +++++-------------- react/containers/ShowChannel/index.js | 51 +++++------ react/containers/ShowChannel/view.jsx | 72 ++++----------- react/reducers/show.js | 44 ++------- react/sagas/request.js | 5 +- react/sagas/show_asset.js | 14 +-- react/sagas/show_channel.js | 22 ++--- 19 files changed, 198 insertions(+), 327 deletions(-) diff --git a/react/actions/show.js b/react/actions/show.js index 49a93c92..bf0d20b3 100644 --- a/react/actions/show.js +++ b/react/actions/show.js @@ -61,24 +61,11 @@ export function showNewAsset (name, claimId) { }; }; -export function updateShowAsset (error, id) { - return { - type: actions.SHOW_ASSET_UPDATE, - data: { error, id }, - }; -}; - -export function clearShowAsset () { - return { - type: actions.SHOW_ASSET_CLEAR, - }; -}; - // add asset to asset list -export function upsertAssetToAssetList (id, error, name, claimId, shortId, claimData) { +export function addAssetToAssetList (id, error, name, claimId, shortId, claimData) { return { - type: actions.ASSET_LIST_UPSERT, + type: actions.ASSET_LIST_ADD, data: { id, error, name, claimId, shortId, claimData }, }; } @@ -101,33 +88,29 @@ export function addChannelRequest (id, error, name, longId, shortId) { // show a channel -export function showNewChannel (channelData) { - const id = `c#${channelData.name}#${channelData.longId}`; // move to the action +export function showNewChannel (name, shortId, longId) { + const id = `c#${name}#${longId}`; // move to the action return { type: actions.SHOW_CHANNEL_NEW, - data: { id, channelData }, + data: { id, name, shortId, longId }, }; }; -export function updateShowChannel (error, id) { - return { - type: actions.SHOW_CHANNEL_UPDATE, - data: { error, id }, - }; -}; +// add channels to channel list -export function clearShowChannel () { +export function addNewChannelToChannelList (id, name, shortId, longId, claimsData) { return { - type: actions.SHOW_CHANNEL_CLEAR, + type: actions.CHANNEL_LIST_ADD, + data: { id, name, shortId, longId, claimsData }, }; }; // update channel data -export function updateChannelClaimsAsync (channelListId, name, longId, page) { +export function updateChannelClaimsAsync (channelKey, name, longId, page) { return { type: actions.CHANNEL_LIST_CLAIMS_UPDATE_ASYNC, - data: {channelListId, name, longId, page}, + data: {channelKey, name, longId, page}, }; }; @@ -138,15 +121,6 @@ export function updateChannelClaims (channelListId, claimsData) { }; }; -// add channels to channel list - -export function addNewChannelToChannelList (id, error, channelData, claimsData) { - return { - type: actions.CHANNEL_LIST_ADD, - data: { id, error, channelData, claimsData }, - }; -}; - // display a file export function fileRequested (name, claimId) { diff --git a/react/components/AssetDisplay/index.js b/react/components/AssetDisplay/index.js index 09fbc0de..c22b28dc 100644 --- a/react/components/AssetDisplay/index.js +++ b/react/components/AssetDisplay/index.js @@ -3,11 +3,18 @@ import View from './view'; import { fileRequested } from 'actions/show'; const mapStateToProps = ({ show }) => { - return { - error : show.displayAsset.error, - status : show.displayAsset.status, - asset : show.assetList[show.showAsset.id], + let props = { + error : show.displayAsset.error, + status: show.displayAsset.status, }; + // select asset info + const existingRequest = show.assetRequests[show.request.id]; + const assetKey = `a#${existingRequest.name}#${existingRequest.claimId}`; + const existingAsset = show.assetList[assetKey]; + if (existingAsset) { + props['asset'] = existingAsset; + }; + return props; }; const mapDispatchToProps = dispatch => { diff --git a/react/components/AssetInfo/index.js b/react/components/AssetInfo/index.js index 899555e6..2614577d 100644 --- a/react/components/AssetInfo/index.js +++ b/react/components/AssetInfo/index.js @@ -2,9 +2,15 @@ import { connect } from 'react-redux'; import View from './view'; const mapStateToProps = ({ show }) => { - return { - asset: show.assetList[show.showAsset.id], + let props = {}; + // select asset info + const request = show.assetRequests[show.request.id]; + const assetKey = `a#${request.name}#${request.claimId}`; + const asset = show.assetList[assetKey]; + if (asset) { + props['asset'] = asset; }; + return props; }; export default connect(mapStateToProps, null)(View); diff --git a/react/components/AssetTitle/index.js b/react/components/AssetTitle/index.js index 9766d497..9be82b66 100644 --- a/react/components/AssetTitle/index.js +++ b/react/components/AssetTitle/index.js @@ -2,9 +2,15 @@ import { connect } from 'react-redux'; import View from './view'; const mapStateToProps = ({ show }) => { - return { - title: show.assetList[show.showAsset.id].claimData.title, + let props = {}; + // select title + const existingRequest = show.assetRequests[show.request.id]; + const assetKey = `a#${existingRequest.name}#${existingRequest.claimId}`; + const existingAsset = show.assetList[assetKey]; + if (existingAsset) { + props['title'] = existingAsset.claimData.title; }; + return props; }; export default connect(mapStateToProps, null)(View); diff --git a/react/components/ShowAssetDetails/index.js b/react/components/ShowAssetDetails/index.js index 899555e6..8cec1202 100644 --- a/react/components/ShowAssetDetails/index.js +++ b/react/components/ShowAssetDetails/index.js @@ -1,10 +1,4 @@ import { connect } from 'react-redux'; import View from './view'; -const mapStateToProps = ({ show }) => { - return { - asset: show.assetList[show.showAsset.id], - }; -}; - -export default connect(mapStateToProps, null)(View); +export default connect(null, null)(View); diff --git a/react/components/ShowAssetDetails/view.jsx b/react/components/ShowAssetDetails/view.jsx index eaef0a1d..8a956774 100644 --- a/react/components/ShowAssetDetails/view.jsx +++ b/react/components/ShowAssetDetails/view.jsx @@ -1,5 +1,4 @@ import React from 'react'; -import PropTypes from 'prop-types'; import NavBar from 'containers/NavBar'; import AssetTitle from 'components/AssetTitle'; import AssetDisplay from 'components/AssetDisplay'; @@ -7,11 +6,9 @@ import AssetInfo from 'components/AssetInfo'; class ShowAssetDetails extends React.Component { render () { - const { asset } = this.props; return (
- {asset &&
@@ -32,8 +29,4 @@ class ShowAssetDetails extends React.Component { } }; -ShowAssetDetails.propTypes = { - error: PropTypes.string, -}; - export default ShowAssetDetails; diff --git a/react/components/ShowAssetLite/index.js b/react/components/ShowAssetLite/index.js index 899555e6..df6a3019 100644 --- a/react/components/ShowAssetLite/index.js +++ b/react/components/ShowAssetLite/index.js @@ -2,9 +2,16 @@ import { connect } from 'react-redux'; import View from './view'; const mapStateToProps = ({ show }) => { - return { - asset: show.assetList[show.showAsset.id], + let props = {}; + // select name and claim id + const existingRequest = show.assetRequests[show.request.id]; + const assetKey = `a#${existingRequest.name}#${existingRequest.claimId}`; + const existingAsset = show.assetList[assetKey]; + if (existingAsset) { + props['name'] = existingAsset.name; + props['claimId'] = existingAsset.claimId; }; + return props; }; export default connect(mapStateToProps, null)(View); diff --git a/react/components/ShowAssetLite/view.jsx b/react/components/ShowAssetLite/view.jsx index d9892d90..74dc1beb 100644 --- a/react/components/ShowAssetLite/view.jsx +++ b/react/components/ShowAssetLite/view.jsx @@ -4,7 +4,7 @@ import AssetDisplay from 'components/AssetDisplay'; class ShowLite extends React.Component { render () { - const { asset: { name, claimId } } = this.props; + const { name, claimId } = this.props; return (
{ (name && claimId) && diff --git a/react/constants/show_action_types.js b/react/constants/show_action_types.js index 732fa8fd..e40455ae 100644 --- a/react/constants/show_action_types.js +++ b/react/constants/show_action_types.js @@ -8,10 +8,7 @@ export const ASSET_REQUEST_NEW = 'ASSET_REQUEST_NEW'; export const ASSET_REQUEST_ADD = 'ASSET_REQUEST_ADD'; export const SHOW_ASSET_NEW = 'SHOW_ASSET_NEW'; -export const SHOW_ASSET_UPDATE = 'SHOW_ASSET_UPDATE'; -export const SHOW_ASSET_CLEAR = 'SHOW_ASSET_CLEAR'; - -export const ASSET_LIST_UPSERT = `ASSET_LIST_UPSERT`; +export const ASSET_LIST_ADD = `ASSET_LIST_ADD`; // channel request actions export const CHANNEL_REQUEST_NEW = 'CHANNEL_REQUEST_NEW'; diff --git a/react/containers/ChannelClaimsDisplay/index.js b/react/containers/ChannelClaimsDisplay/index.js index 392f446d..4c9bd356 100644 --- a/react/containers/ChannelClaimsDisplay/index.js +++ b/react/containers/ChannelClaimsDisplay/index.js @@ -3,16 +3,23 @@ import { updateChannelClaimsAsync } from 'actions/show'; import View from './view'; const mapStateToProps = ({ show }) => { - return { - showChannelId: show.showChannel.id, - channel : show.channelList[show.showChannel.id], + let props = {}; + // select channel key + const request = show.channelRequests[show.request.id]; + const channelKey = `c#${request.name}#${request.longId}`; + props['channelKey'] = channelKey; + // select channel claims + const channel = show.channelList[channelKey]; + if (channel) { + props['channel'] = channel; }; + return props; }; const mapDispatchToProps = dispatch => { return { - onChannelPageUpdate: (showChannelId, name, longId, page) => { - dispatch(updateChannelClaimsAsync(showChannelId, name, longId, page)); + onChannelPageUpdate: (channelKey, name, longId, page) => { + dispatch(updateChannelClaimsAsync(channelKey, name, longId, page)); }, }; }; diff --git a/react/containers/ChannelClaimsDisplay/view.jsx b/react/containers/ChannelClaimsDisplay/view.jsx index 0f3aacab..4dbcce27 100644 --- a/react/containers/ChannelClaimsDisplay/view.jsx +++ b/react/containers/ChannelClaimsDisplay/view.jsx @@ -18,43 +18,32 @@ class ChannelClaimsDisplay extends React.Component { this.showNewPage(nextPage); } showNewPage (page) { - const { showChannelId, channel: { channelData: { name, longId } } } = this.props; - console.log(`update claims data on channel ${showChannelId} with new page ${page}`); - this.props.onChannelPageUpdate(showChannelId, name, longId, page); + const { channelKey, channel: { name, longId } } = this.props; + this.props.onChannelPageUpdate(channelKey, name, longId, page); } render () { - const { channel: { error, claimsData: { claims, currentPage, totalPages } } } = this.props; + const { channel: { claimsData: { claims, currentPage, totalPages } } } = this.props; return ( -
- {error ? ( -
-
-

{error}

-
-
- ) : ( -
- {claims && -
- {claims.map((claim, index) => )} -
- {(currentPage > 1) && - - } - {(currentPage < totalPages) && - - } -
-
+
+ {claims && +
+ {claims.map((claim, index) => )} +
+ {(currentPage > 1) && + + } + {(currentPage < totalPages) && + }
- )} +
+ }
); } diff --git a/react/containers/ShowAsset/index.js b/react/containers/ShowAsset/index.js index e375e2ab..63ccfa97 100644 --- a/react/containers/ShowAsset/index.js +++ b/react/containers/ShowAsset/index.js @@ -1,20 +1,27 @@ import { connect } from 'react-redux'; import View from './view'; -import { newAssetRequest, updateRequestError, showNewAsset, updateShowAsset, clearShowAsset } from 'actions/show'; +import { newAssetRequest, showNewAsset } from 'actions/show'; const mapStateToProps = ({ show }) => { - return { - // request - requestId : show.request.id, - requestName : show.request.data.name, - requestModifier : show.request.data.modifier, - requestExtension: show.request.data.extension, - assetRequests : show.assetRequests, - assetList : show.assetList, - // show asset - error : show.showAsset.error, - id : show.showAsset.id, + let props = {}; + props['requestType'] = show.request.type; + props['requestId'] = show.request.id; + props['requestName'] = show.request.data.name; + props['requestModifier'] = show.request.data.modifier; + props['requestExtension'] = show.request.data.extension; + // select request + const existingRequest = show.assetRequests[show.request.id]; + if (existingRequest) { + props['existingRequest'] = existingRequest; + // select asset info + const assetKey = `a#${existingRequest.name}#${existingRequest.claimId}`; // note: just store this in the request + const existingAsset = show.assetList[assetKey]; + if (existingAsset) { + console.log('existing asset found', existingAsset); + props['asset'] = existingAsset; + }; }; + return props; }; const mapDispatchToProps = dispatch => { @@ -23,19 +30,10 @@ const mapDispatchToProps = dispatch => { onNewRequest: (id, name, modifier) => { dispatch(newAssetRequest(id, name, modifier)); }, - onRequestError: (error) => { - dispatch(updateRequestError(error, null, null)); - }, // show asset onShowNewAsset: (name, claimId) => { dispatch(showNewAsset(name, claimId)); }, - onShowExistingAsset: (assetId) => { - dispatch(updateShowAsset(null, assetId)); - }, - onLeaveShowAsset: () => { - dispatch(clearShowAsset()); // clear any errors - }, }; }; diff --git a/react/containers/ShowAsset/view.jsx b/react/containers/ShowAsset/view.jsx index 3e3de33d..87f75a91 100644 --- a/react/containers/ShowAsset/view.jsx +++ b/react/containers/ShowAsset/view.jsx @@ -9,83 +9,40 @@ function requestIsAnAssetRequest ({ requestType }) { return requestType === ASSET; } -function requestIsNewRequest (nextProps, props) { - return (nextProps.requestId !== props.requestId); -} - class ShowAsset extends React.Component { componentDidMount () { - const { requestId, requestName, requestModifier, assetRequests } = this.props; - const existingRequest = assetRequests[requestId]; - if (existingRequest) { // case: the assetRequest exists - this.onRepeatRequest(existingRequest); - } else { // case: the asset request does not exist - this.onNewRequest(requestId, requestName, requestModifier); - } + const { asset, existingRequest, requestId, requestName, requestModifier } = this.props; + if (!existingRequest) { // case: the asset request does not exist + return this.props.onNewRequest(requestId, requestName, requestModifier); + }; + if (!asset) { // case: the asset request does not exist + const { name, claimId } = existingRequest; + return this.props.onShowNewAsset(name, claimId); + }; } componentWillReceiveProps (nextProps) { - // case where componentDidMount triggered new props - if (requestIsAnAssetRequest(nextProps) && requestIsNewRequest(nextProps, this.props)) { - const { requestId, requestName, requestModifier, assetRequests } = nextProps; - const existingRequest = assetRequests[requestId]; - if (existingRequest) { // case: the assetRequest exists - this.onRepeatRequest(existingRequest); - } else { // case: the asset request does not exist - this.onNewRequest(requestId, requestName, requestModifier); - } - } else { - console.log('ShowAsset receiving new props -> request.id did not update', nextProps); + if (requestIsAnAssetRequest(nextProps)) { + const { asset, existingRequest, requestId, requestName, requestModifier } = nextProps; + if (!existingRequest) { + return this.props.onNewRequest(requestId, requestName, requestModifier); + }; + if (!asset) { + const { name, claimId } = existingRequest; + return this.props.onShowNewAsset(name, claimId); + }; } } - onNewRequest (id, requestName, requestModifier) { - console.log('new request'); - this.props.onNewRequest(id, requestName, requestModifier); - } - onRepeatRequest ({ error, name, claimId }) { - console.log('repeat request'); - // if error, return and update state with error - if (error) { - return this.props.onRequestError(error); - } - // update the showAsset data in the store - const { assetList } = this.props; - const assetId = `a#${name}#${claimId}`; - const existingAssetRecord = assetList[assetId]; - if (existingAssetRecord) { // case: the asset data already exists - this.showExistingAsset(assetId); - } else { // case: the asset data does not exist yet - this.showNewAsset(name, claimId); - } - } - showNewAsset (name, claimId) { - this.props.onShowNewAsset(name, claimId); - } - showExistingAsset (assetId) { - this.props.onShowExistingAsset(assetId); - } - componentWillUnmount () { - this.props.onLeaveShowAsset(); - } render () { - const { error, id, requestExtension } = this.props; - if (error) { - return ( - - ); - } - if (id) { // direct requests are passing because name is present so it just goes + const {asset, requestExtension} = this.props; + if (asset) { if (requestExtension) { - return ( - - ); - } else { - return ( - - ); + return ; } - }; + return ; + } + ; return ( -
+ ); } }; diff --git a/react/containers/ShowChannel/index.js b/react/containers/ShowChannel/index.js index 619a5966..7ddfef82 100644 --- a/react/containers/ShowChannel/index.js +++ b/react/containers/ShowChannel/index.js @@ -1,41 +1,38 @@ + import { connect } from 'react-redux'; -import {newChannelRequest, updateRequestError, showNewChannel, updateShowChannel, clearShowChannel} from 'actions/show'; +import { newChannelRequest, showNewChannel } from 'actions/show'; import View from './view'; const mapStateToProps = ({ show }) => { - return { - // request - requestId : show.request.id, - requestType : show.request.type, - requestChannelName: show.request.data.name, - requestChannelId : show.request.data.id, - requestList : show.channelRequests, - channelList : show.channelList, - // show channel - error : show.showChannel.error, - id : show.showChannel.id, - channel : show.channelList[show.showChannel.id], - }; + let props = {}; + props['requestId'] = show.request.id; + props['requestType'] = show.request.type; + props['requestChannelName'] = show.request.data.name; + props['requestChannelId'] = show.request.data.id; + // select request + const existingRequest = show.channelRequests[show.request.id]; + if (existingRequest) { + props['existingRequest'] = existingRequest; + console.log('existing channel request found', existingRequest); + // select channel info + const channelKey = `c#${existingRequest.name}#${existingRequest.longId}`; + const channel = show.channelList[channelKey]; + if (channel) { + props['channel'] = channel; + }; + } + return props; }; const mapDispatchToProps = dispatch => { return { // request - onNewChannelRequest (id, name, channelId) { - dispatch(newChannelRequest(id, name, channelId)); - }, - onRequestError: (error) => { - dispatch(updateRequestError(error, null, null)); + onNewChannelRequest (requestId, requestChannelName, requestChannelId) { + dispatch(newChannelRequest(requestId, requestChannelName, requestChannelId)); }, // show channel - onShowNewChannel: (channelData) => { - dispatch(showNewChannel(channelData)); - }, - onShowExistingChannel: (id) => { - dispatch(updateShowChannel(null, id)); - }, - onShowChannelClear: () => { - dispatch(clearShowChannel()); + onShowNewChannel: (name, shortId, longId) => { + dispatch(showNewChannel(name, shortId, longId)); }, }; }; diff --git a/react/containers/ShowChannel/view.jsx b/react/containers/ShowChannel/view.jsx index 16962e9d..497faab5 100644 --- a/react/containers/ShowChannel/view.jsx +++ b/react/containers/ShowChannel/view.jsx @@ -9,69 +9,33 @@ function requestIsAChannelRequest ({ requestType }) { return requestType === CHANNEL; } -function requestIsNewRequest (nextProps, props) { - return (nextProps.requestId !== props.requestId); -} - class ShowChannel extends React.Component { componentDidMount () { - const {requestId, requestChannelName, requestChannelId, requestList, channelList} = this.props; - const existingRequest = requestList[requestId]; - if (existingRequest) { - this.onRepeatChannelRequest(existingRequest, channelList); - } else { - this.onNewChannelRequest(requestId, requestChannelName, requestChannelId); + const { existingRequest, channel, requestId, requestChannelName, requestChannelId } = this.props; + if (!existingRequest) { + return this.props.onNewChannelRequest(requestId, requestChannelName, requestChannelId); + } + if (!channel) { + const { name, shortId, longId } = existingRequest; + return this.props.onShowNewChannel(name, shortId, longId); } } componentWillReceiveProps (nextProps) { - if (requestIsAChannelRequest(nextProps) && requestIsNewRequest(nextProps, this.props)) { - const {requestId, requestChannelName, requestChannelId, requestList, channelList} = nextProps; - const existingRequest = requestList[requestId]; - if (existingRequest) { - this.onRepeatChannelRequest(existingRequest, channelList); - } else { - this.onNewChannelRequest(requestId, requestChannelName, requestChannelId); + if (requestIsAChannelRequest(nextProps)) { + const { existingRequest, channel, requestId, requestChannelName, requestChannelId } = nextProps; + if (!existingRequest) { + return this.props.onNewChannelRequest(requestId, requestChannelName, requestChannelId); + } + if (!channel) { + const { name, shortId, longId } = existingRequest; + return this.props.onShowNewChannel(name, shortId, longId); } - } else { - console.log('ShowChannel receiving new props -> request.id did not update', nextProps); - }; - } - onNewChannelRequest (requestId, requestName, requestChannelId) { - console.log('new request'); - this.props.onNewChannelRequest(requestId, requestName, requestChannelId); - } - onRepeatChannelRequest ({ error, channelData }, channelList) { - // if error, return and update state with error - if (error) { - return this.props.onRequestError(error); } - // check if the channel data is present or not - const channelRecordId = `c#${channelData.name}#${channelData.longId}`; - const existingChannel = channelList[channelRecordId]; - if (existingChannel) { - this.showExistingChannel(channelRecordId); - } else { - this.showNewChannel(channelData); - } - } - showNewChannel (channelData) { - this.props.onShowNewChannel(channelData); - }; - showExistingChannel (channelRecordId) { - this.props.onShowExistingChannel(channelRecordId); - }; - componentWillUnmount () { - this.props.onShowChannelClear(); } render () { - const { error, channel } = this.props; - if (error) { - return ( - - ); - }; + const { channel } = this.props; if (channel) { - const { channelData: { name, longId, shortId } } = channel; + const { name, longId, shortId } = channel; return (
@@ -82,7 +46,7 @@ class ShowChannel extends React.Component {

short channel id: {shortId ? shortId : 'loading...'}

- {(name && longId) && } +
diff --git a/react/reducers/show.js b/react/reducers/show.js index 6a1b32df..d5b8eb5c 100644 --- a/react/reducers/show.js +++ b/react/reducers/show.js @@ -9,14 +9,6 @@ const initialState = { data : null, requestId: null, }, - showChannel: { - error: null, - id : null, - }, - showAsset: { - error: null, - id : null, - }, displayAsset: { error : null, status: LOCAL_CHECK, @@ -24,7 +16,7 @@ const initialState = { channelRequests: {}, channelList : {}, assetRequests : {}, - assetList : {}, // same schema as showAsset + assetList : {}, }; export default function (state = initialState, action) { @@ -72,23 +64,8 @@ export default function (state = initialState, action) { }, }), }); - // show an asset - case actions.SHOW_ASSET_UPDATE: - return Object.assign({}, state, { - showAsset: Object.assign({}, state.showAsset, { - error: action.data.error, - id : action.data.id, - }), - }); - case actions.SHOW_ASSET_CLEAR: - return Object.assign({}, state, { - showAsset: Object.assign({}, state.showAsset, { - error: null, - id : null, - }), - }); // add asset to asset list - case actions.ASSET_LIST_UPSERT: + case actions.ASSET_LIST_ADD: return Object.assign({}, state, { assetList: Object.assign({}, state.assetList, { [action.data.id]: { @@ -105,12 +82,10 @@ export default function (state = initialState, action) { return Object.assign({}, state, { channelRequests: Object.assign({}, state.channelRequests, { [action.data.id]: { - error : action.data.error, - channelData: { - name : action.data.name, - longId : action.data.longId, - shortId: action.data.shortId, - }, + error : action.data.error, + name : action.data.name, + longId : action.data.longId, + shortId: action.data.shortId, }, }), }); @@ -134,9 +109,10 @@ export default function (state = initialState, action) { return Object.assign({}, state, { channelList: Object.assign({}, state.channelList, { [action.data.id]: { - error : action.data.error, - channelData: action.data.channelData, - claimsData : action.data.claimsData, + name : action.data.name, + longId : action.data.longId, + shortId : action.data.shortId, + claimsData: action.data.claimsData, }, }), }); diff --git a/react/sagas/request.js b/react/sagas/request.js index 8ebc96f9..bab66c88 100644 --- a/react/sagas/request.js +++ b/react/sagas/request.js @@ -26,7 +26,7 @@ function* newChannelRequest (action) { ({success, message, data} = yield call(getChannelData, name, channelId)); } catch (error) { // return yield put(addChannelRequest(id, error.message, null, null, null)); - return yield put(updateRequestError(message)); + return yield put(updateRequestError(error.message)); } if (!success) { // return yield put(addChannelRequest(id, message, null, null, null)); @@ -34,8 +34,7 @@ function* newChannelRequest (action) { } const { longChannelClaimId: longId, shortChannelClaimId: shortId } = data; yield put(addChannelRequest(id, null, name, longId, shortId)); - const channelData = {name, longId, shortId}; - yield put(showNewChannel(channelData)); + yield put(showNewChannel(name, shortId, longId)); } export function* watchNewAssetRequest () { diff --git a/react/sagas/show_asset.js b/react/sagas/show_asset.js index d9b1d991..b6931b72 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 { updateShowAsset, upsertAssetToAssetList } from 'actions/show'; +import { updateRequestError, addAssetToAssetList } from 'actions/show'; import { getShortId, getClaimData } from 'api/assetApi'; function* getAssetDataAndShowAsset (action) { @@ -10,10 +10,10 @@ function* getAssetDataAndShowAsset (action) { try { ({success, message, data: shortId} = yield call(getShortId, name, claimId)); } catch (error) { - return yield put(updateShowAsset(error.message, null)); + return yield put(updateRequestError(error.message)); } if (!success) { - return yield put(updateShowAsset(message, null)); + return yield put(updateRequestError(message)); } // if no error, get claim data success = null; @@ -21,13 +21,13 @@ function* getAssetDataAndShowAsset (action) { try { ({success, message, data: claimData} = yield call(getClaimData, name, claimId)); } catch (error) { - return yield put(updateShowAsset(error.message, null)); + return yield put(updateRequestError(error.message)); } if (!success) { - return yield put(updateShowAsset(message, null)); + return yield put(updateRequestError(message)); } - yield put(upsertAssetToAssetList(id, null, name, claimId, shortId, claimData)); - yield put(updateShowAsset(null, id)); + yield put(addAssetToAssetList(id, null, name, claimId, shortId, claimData)); + yield put(updateRequestError(null)); } export function* watchShowNewAsset () { diff --git a/react/sagas/show_channel.js b/react/sagas/show_channel.js index 9b328e99..c86906b9 100644 --- a/react/sagas/show_channel.js +++ b/react/sagas/show_channel.js @@ -1,22 +1,22 @@ import { call, put, takeLatest } from 'redux-saga/effects'; import * as actions from 'constants/show_action_types'; -import { updateShowChannel, addNewChannelToChannelList, updateChannelClaims } from 'actions/show'; +import { updateRequestError, addNewChannelToChannelList, updateChannelClaims } from 'actions/show'; import { getChannelClaims } from 'api/channelApi'; function* getChannelClaimsAndShowChannel (action) { - const { id, channelData: {name, shortId, longId} } = action.data; + const { id, name, shortId, longId } = action.data; + console.log('getchannelclaimsandshowchannel', id, name, shortId, longId); let success, message, claimsData; try { ({ success, message, data: claimsData } = yield call(getChannelClaims, name, longId, 1)); } catch (error) { - return yield put(updateShowChannel(error.message, null)); + return yield put(updateRequestError(error.message)); } if (!success) { - return yield put(updateShowChannel(message, null)); + return yield put(updateRequestError(message)); } - const channelData = {name, shortId, longId}; - yield put(addNewChannelToChannelList(id, null, channelData, claimsData)); - yield put(updateShowChannel(null, id)); + yield put(addNewChannelToChannelList(id, name, shortId, longId, claimsData)); + yield put(updateRequestError(null)); } export function* watchShowNewChannel () { @@ -24,17 +24,17 @@ export function* watchShowNewChannel () { }; function* getNewClaimsAndUpdateClaimsList (action) { - const { channelListId, name, longId, page } = action.data; + const { channelKey, name, longId, page } = action.data; let success, message, claimsData; try { ({ success, message, data: claimsData } = yield call(getChannelClaims, name, longId, page)); } catch (error) { - return yield put(updateShowChannel(error.message, null)); + return yield put(updateRequestError(error.message)); } if (!success) { - return yield put(updateShowChannel(message, null)); + return yield put(updateRequestError(message)); } - yield put(updateChannelClaims(channelListId, claimsData)); + yield put(updateChannelClaims(channelKey, claimsData)); } export function* watchShowNewChannelClaimsRequest () {