moved channel selection logic to mapStateToProps

This commit is contained in:
bill bittner 2018-02-12 18:18:56 -08:00
parent afe95916c1
commit 249b6c6f0f
19 changed files with 198 additions and 327 deletions

View file

@ -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 // add asset to asset list
export function upsertAssetToAssetList (id, error, name, claimId, shortId, claimData) { export function addAssetToAssetList (id, error, name, claimId, shortId, claimData) {
return { return {
type: actions.ASSET_LIST_UPSERT, type: actions.ASSET_LIST_ADD,
data: { id, error, name, claimId, shortId, claimData }, data: { id, error, name, claimId, shortId, claimData },
}; };
} }
@ -101,33 +88,29 @@ export function addChannelRequest (id, error, name, longId, shortId) {
// show a channel // show a channel
export function showNewChannel (channelData) { export function showNewChannel (name, shortId, longId) {
const id = `c#${channelData.name}#${channelData.longId}`; // move to the action const id = `c#${name}#${longId}`; // move to the action
return { return {
type: actions.SHOW_CHANNEL_NEW, type: actions.SHOW_CHANNEL_NEW,
data: { id, channelData }, data: { id, name, shortId, longId },
}; };
}; };
export function updateShowChannel (error, id) { // add channels to channel list
return {
type: actions.SHOW_CHANNEL_UPDATE,
data: { error, id },
};
};
export function clearShowChannel () { export function addNewChannelToChannelList (id, name, shortId, longId, claimsData) {
return { return {
type: actions.SHOW_CHANNEL_CLEAR, type: actions.CHANNEL_LIST_ADD,
data: { id, name, shortId, longId, claimsData },
}; };
}; };
// update channel data // update channel data
export function updateChannelClaimsAsync (channelListId, name, longId, page) { export function updateChannelClaimsAsync (channelKey, name, longId, page) {
return { return {
type: actions.CHANNEL_LIST_CLAIMS_UPDATE_ASYNC, 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 // display a file
export function fileRequested (name, claimId) { export function fileRequested (name, claimId) {

View file

@ -3,11 +3,18 @@ import View from './view';
import { fileRequested } from 'actions/show'; import { fileRequested } from 'actions/show';
const mapStateToProps = ({ show }) => { const mapStateToProps = ({ show }) => {
return { let props = {
error : show.displayAsset.error, error : show.displayAsset.error,
status: show.displayAsset.status, status: show.displayAsset.status,
asset : show.assetList[show.showAsset.id],
}; };
// 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 => { const mapDispatchToProps = dispatch => {

View file

@ -2,9 +2,15 @@ import { connect } from 'react-redux';
import View from './view'; import View from './view';
const mapStateToProps = ({ show }) => { const mapStateToProps = ({ show }) => {
return { let props = {};
asset: show.assetList[show.showAsset.id], // 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); export default connect(mapStateToProps, null)(View);

View file

@ -2,9 +2,15 @@ import { connect } from 'react-redux';
import View from './view'; import View from './view';
const mapStateToProps = ({ show }) => { const mapStateToProps = ({ show }) => {
return { let props = {};
title: show.assetList[show.showAsset.id].claimData.title, // 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); export default connect(mapStateToProps, null)(View);

View file

@ -1,10 +1,4 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import View from './view'; import View from './view';
const mapStateToProps = ({ show }) => { export default connect(null, null)(View);
return {
asset: show.assetList[show.showAsset.id],
};
};
export default connect(mapStateToProps, null)(View);

View file

@ -1,5 +1,4 @@
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types';
import NavBar from 'containers/NavBar'; import NavBar from 'containers/NavBar';
import AssetTitle from 'components/AssetTitle'; import AssetTitle from 'components/AssetTitle';
import AssetDisplay from 'components/AssetDisplay'; import AssetDisplay from 'components/AssetDisplay';
@ -7,11 +6,9 @@ import AssetInfo from 'components/AssetInfo';
class ShowAssetDetails extends React.Component { class ShowAssetDetails extends React.Component {
render () { render () {
const { asset } = this.props;
return ( return (
<div> <div>
<NavBar/> <NavBar/>
{asset &&
<div className="row row--tall row--padded"> <div className="row row--tall row--padded">
<div className="column column--10"> <div className="column column--10">
<AssetTitle /> <AssetTitle />
@ -32,8 +29,4 @@ class ShowAssetDetails extends React.Component {
} }
}; };
ShowAssetDetails.propTypes = {
error: PropTypes.string,
};
export default ShowAssetDetails; export default ShowAssetDetails;

View file

@ -2,9 +2,16 @@ import { connect } from 'react-redux';
import View from './view'; import View from './view';
const mapStateToProps = ({ show }) => { const mapStateToProps = ({ show }) => {
return { let props = {};
asset: show.assetList[show.showAsset.id], // 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); export default connect(mapStateToProps, null)(View);

View file

@ -4,7 +4,7 @@ import AssetDisplay from 'components/AssetDisplay';
class ShowLite extends React.Component { class ShowLite extends React.Component {
render () { render () {
const { asset: { name, claimId } } = this.props; const { name, claimId } = this.props;
return ( return (
<div className="row row--tall flex-container--column flex-container--center-center"> <div className="row row--tall flex-container--column flex-container--center-center">
{ (name && claimId) && { (name && claimId) &&

View file

@ -8,10 +8,7 @@ export const ASSET_REQUEST_NEW = 'ASSET_REQUEST_NEW';
export const ASSET_REQUEST_ADD = 'ASSET_REQUEST_ADD'; export const ASSET_REQUEST_ADD = 'ASSET_REQUEST_ADD';
export const SHOW_ASSET_NEW = 'SHOW_ASSET_NEW'; export const SHOW_ASSET_NEW = 'SHOW_ASSET_NEW';
export const SHOW_ASSET_UPDATE = 'SHOW_ASSET_UPDATE'; export const ASSET_LIST_ADD = `ASSET_LIST_ADD`;
export const SHOW_ASSET_CLEAR = 'SHOW_ASSET_CLEAR';
export const ASSET_LIST_UPSERT = `ASSET_LIST_UPSERT`;
// channel request actions // channel request actions
export const CHANNEL_REQUEST_NEW = 'CHANNEL_REQUEST_NEW'; export const CHANNEL_REQUEST_NEW = 'CHANNEL_REQUEST_NEW';

View file

@ -3,16 +3,23 @@ import { updateChannelClaimsAsync } from 'actions/show';
import View from './view'; import View from './view';
const mapStateToProps = ({ show }) => { const mapStateToProps = ({ show }) => {
return { let props = {};
showChannelId: show.showChannel.id, // select channel key
channel : show.channelList[show.showChannel.id], 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 => { const mapDispatchToProps = dispatch => {
return { return {
onChannelPageUpdate: (showChannelId, name, longId, page) => { onChannelPageUpdate: (channelKey, name, longId, page) => {
dispatch(updateChannelClaimsAsync(showChannelId, name, longId, page)); dispatch(updateChannelClaimsAsync(channelKey, name, longId, page));
}, },
}; };
}; };

View file

@ -18,21 +18,12 @@ class ChannelClaimsDisplay extends React.Component {
this.showNewPage(nextPage); this.showNewPage(nextPage);
} }
showNewPage (page) { showNewPage (page) {
const { showChannelId, channel: { channelData: { name, longId } } } = this.props; const { channelKey, channel: { name, longId } } = this.props;
console.log(`update claims data on channel ${showChannelId} with new page ${page}`); this.props.onChannelPageUpdate(channelKey, name, longId, page);
this.props.onChannelPageUpdate(showChannelId, name, longId, page);
} }
render () { render () {
const { channel: { error, claimsData: { claims, currentPage, totalPages } } } = this.props; const { channel: { claimsData: { claims, currentPage, totalPages } } } = this.props;
return ( return (
<div>
{error ? (
<div className="row">
<div className="column column--10">
<p>{error}</p>
</div>
</div>
) : (
<div className="row row--tall"> <div className="row row--tall">
{claims && {claims &&
<div> <div>
@ -54,8 +45,6 @@ class ChannelClaimsDisplay extends React.Component {
</div> </div>
} }
</div> </div>
)}
</div>
); );
} }
}; };

View file

@ -1,21 +1,28 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import View from './view'; import View from './view';
import { newAssetRequest, updateRequestError, showNewAsset, updateShowAsset, clearShowAsset } from 'actions/show'; import { newAssetRequest, showNewAsset } from 'actions/show';
const mapStateToProps = ({ show }) => { const mapStateToProps = ({ show }) => {
return { let props = {};
// request props['requestType'] = show.request.type;
requestId : show.request.id, props['requestId'] = show.request.id;
requestName : show.request.data.name, props['requestName'] = show.request.data.name;
requestModifier : show.request.data.modifier, props['requestModifier'] = show.request.data.modifier;
requestExtension: show.request.data.extension, props['requestExtension'] = show.request.data.extension;
assetRequests : show.assetRequests, // select request
assetList : show.assetList, const existingRequest = show.assetRequests[show.request.id];
// show asset if (existingRequest) {
error : show.showAsset.error, props['existingRequest'] = existingRequest;
id : show.showAsset.id, // 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 => { const mapDispatchToProps = dispatch => {
return { return {
@ -23,19 +30,10 @@ const mapDispatchToProps = dispatch => {
onNewRequest: (id, name, modifier) => { onNewRequest: (id, name, modifier) => {
dispatch(newAssetRequest(id, name, modifier)); dispatch(newAssetRequest(id, name, modifier));
}, },
onRequestError: (error) => {
dispatch(updateRequestError(error, null, null));
},
// show asset // show asset
onShowNewAsset: (name, claimId) => { onShowNewAsset: (name, claimId) => {
dispatch(showNewAsset(name, claimId)); dispatch(showNewAsset(name, claimId));
}, },
onShowExistingAsset: (assetId) => {
dispatch(updateShowAsset(null, assetId));
},
onLeaveShowAsset: () => {
dispatch(clearShowAsset()); // clear any errors
},
}; };
}; };

View file

@ -9,83 +9,40 @@ function requestIsAnAssetRequest ({ requestType }) {
return requestType === ASSET; return requestType === ASSET;
} }
function requestIsNewRequest (nextProps, props) {
return (nextProps.requestId !== props.requestId);
}
class ShowAsset extends React.Component { class ShowAsset extends React.Component {
componentDidMount () { componentDidMount () {
const { requestId, requestName, requestModifier, assetRequests } = this.props; const { asset, existingRequest, requestId, requestName, requestModifier } = this.props;
const existingRequest = assetRequests[requestId]; if (!existingRequest) { // case: the asset request does not exist
if (existingRequest) { // case: the assetRequest exists return this.props.onNewRequest(requestId, requestName, requestModifier);
this.onRepeatRequest(existingRequest); };
} else { // case: the asset request does not exist if (!asset) { // case: the asset request does not exist
this.onNewRequest(requestId, requestName, requestModifier); const { name, claimId } = existingRequest;
} return this.props.onShowNewAsset(name, claimId);
};
} }
componentWillReceiveProps (nextProps) { componentWillReceiveProps (nextProps) {
// case where componentDidMount triggered new props if (requestIsAnAssetRequest(nextProps)) {
if (requestIsAnAssetRequest(nextProps) && requestIsNewRequest(nextProps, this.props)) { const { asset, existingRequest, requestId, requestName, requestModifier } = nextProps;
const { requestId, requestName, requestModifier, assetRequests } = nextProps; if (!existingRequest) {
const existingRequest = assetRequests[requestId]; return this.props.onNewRequest(requestId, requestName, requestModifier);
if (existingRequest) { // case: the assetRequest exists };
this.onRepeatRequest(existingRequest); if (!asset) {
} else { // case: the asset request does not exist const { name, claimId } = existingRequest;
this.onNewRequest(requestId, requestName, requestModifier); return this.props.onShowNewAsset(name, claimId);
};
} }
} else {
console.log('ShowAsset receiving new props -> request.id did not update', nextProps);
}
}
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 () { render () {
const { error, id, requestExtension } = this.props; const {asset, requestExtension} = this.props;
if (error) { if (asset) {
return (
<ErrorPage error={error}/>
);
}
if (id) { // direct requests are passing because name is present so it just goes
if (requestExtension) { if (requestExtension) {
return ( return <ShowAssetLite/>;
<ShowAssetLite />
);
} else {
return (
<ShowAssetDetails />
);
} }
}; return <ShowAssetDetails/>;
}
;
return ( return (
<div> </div> <ErrorPage error={'loading asset data...'}/>
); );
} }
}; };

View file

@ -1,41 +1,38 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import {newChannelRequest, updateRequestError, showNewChannel, updateShowChannel, clearShowChannel} from 'actions/show'; import { newChannelRequest, showNewChannel } from 'actions/show';
import View from './view'; import View from './view';
const mapStateToProps = ({ show }) => { const mapStateToProps = ({ show }) => {
return { let props = {};
// request props['requestId'] = show.request.id;
requestId : show.request.id, props['requestType'] = show.request.type;
requestType : show.request.type, props['requestChannelName'] = show.request.data.name;
requestChannelName: show.request.data.name, props['requestChannelId'] = show.request.data.id;
requestChannelId : show.request.data.id, // select request
requestList : show.channelRequests, const existingRequest = show.channelRequests[show.request.id];
channelList : show.channelList, if (existingRequest) {
// show channel props['existingRequest'] = existingRequest;
error : show.showChannel.error, console.log('existing channel request found', existingRequest);
id : show.showChannel.id, // select channel info
channel : show.channelList[show.showChannel.id], const channelKey = `c#${existingRequest.name}#${existingRequest.longId}`;
const channel = show.channelList[channelKey];
if (channel) {
props['channel'] = channel;
}; };
}
return props;
}; };
const mapDispatchToProps = dispatch => { const mapDispatchToProps = dispatch => {
return { return {
// request // request
onNewChannelRequest (id, name, channelId) { onNewChannelRequest (requestId, requestChannelName, requestChannelId) {
dispatch(newChannelRequest(id, name, channelId)); dispatch(newChannelRequest(requestId, requestChannelName, requestChannelId));
},
onRequestError: (error) => {
dispatch(updateRequestError(error, null, null));
}, },
// show channel // show channel
onShowNewChannel: (channelData) => { onShowNewChannel: (name, shortId, longId) => {
dispatch(showNewChannel(channelData)); dispatch(showNewChannel(name, shortId, longId));
},
onShowExistingChannel: (id) => {
dispatch(updateShowChannel(null, id));
},
onShowChannelClear: () => {
dispatch(clearShowChannel());
}, },
}; };
}; };

View file

@ -9,69 +9,33 @@ function requestIsAChannelRequest ({ requestType }) {
return requestType === CHANNEL; return requestType === CHANNEL;
} }
function requestIsNewRequest (nextProps, props) {
return (nextProps.requestId !== props.requestId);
}
class ShowChannel extends React.Component { class ShowChannel extends React.Component {
componentDidMount () { componentDidMount () {
const {requestId, requestChannelName, requestChannelId, requestList, channelList} = this.props; const { existingRequest, channel, requestId, requestChannelName, requestChannelId } = this.props;
const existingRequest = requestList[requestId]; if (!existingRequest) {
if (existingRequest) { return this.props.onNewChannelRequest(requestId, requestChannelName, requestChannelId);
this.onRepeatChannelRequest(existingRequest, channelList); }
} else { if (!channel) {
this.onNewChannelRequest(requestId, requestChannelName, requestChannelId); const { name, shortId, longId } = existingRequest;
return this.props.onShowNewChannel(name, shortId, longId);
} }
} }
componentWillReceiveProps (nextProps) { componentWillReceiveProps (nextProps) {
if (requestIsAChannelRequest(nextProps) && requestIsNewRequest(nextProps, this.props)) { if (requestIsAChannelRequest(nextProps)) {
const {requestId, requestChannelName, requestChannelId, requestList, channelList} = nextProps; const { existingRequest, channel, requestId, requestChannelName, requestChannelId } = nextProps;
const existingRequest = requestList[requestId]; if (!existingRequest) {
if (existingRequest) { return this.props.onNewChannelRequest(requestId, requestChannelName, requestChannelId);
this.onRepeatChannelRequest(existingRequest, channelList);
} else {
this.onNewChannelRequest(requestId, requestChannelName, requestChannelId);
} }
} else { if (!channel) {
console.log('ShowChannel receiving new props -> request.id did not update', nextProps); const { name, shortId, longId } = existingRequest;
}; return this.props.onShowNewChannel(name, shortId, longId);
}
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 () { render () {
const { error, channel } = this.props; const { channel } = this.props;
if (error) {
return (
<ErrorPage error={error}/>
);
};
if (channel) { if (channel) {
const { channelData: { name, longId, shortId } } = channel; const { name, longId, shortId } = channel;
return ( return (
<div> <div>
<NavBar/> <NavBar/>
@ -82,7 +46,7 @@ class ShowChannel extends React.Component {
<p className={'fine-print'}>short channel id: {shortId ? shortId : 'loading...'}</p> <p className={'fine-print'}>short channel id: {shortId ? shortId : 'loading...'}</p>
</div> </div>
<div className="column column--10"> <div className="column column--10">
{(name && longId) && <ChannelClaimsDisplay />} <ChannelClaimsDisplay />
</div> </div>
</div> </div>
</div> </div>

View file

@ -9,14 +9,6 @@ const initialState = {
data : null, data : null,
requestId: null, requestId: null,
}, },
showChannel: {
error: null,
id : null,
},
showAsset: {
error: null,
id : null,
},
displayAsset: { displayAsset: {
error : null, error : null,
status: LOCAL_CHECK, status: LOCAL_CHECK,
@ -24,7 +16,7 @@ const initialState = {
channelRequests: {}, channelRequests: {},
channelList : {}, channelList : {},
assetRequests : {}, assetRequests : {},
assetList : {}, // same schema as showAsset assetList : {},
}; };
export default function (state = initialState, action) { 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 // add asset to asset list
case actions.ASSET_LIST_UPSERT: case actions.ASSET_LIST_ADD:
return Object.assign({}, state, { return Object.assign({}, state, {
assetList: Object.assign({}, state.assetList, { assetList: Object.assign({}, state.assetList, {
[action.data.id]: { [action.data.id]: {
@ -106,12 +83,10 @@ export default function (state = initialState, action) {
channelRequests: Object.assign({}, state.channelRequests, { channelRequests: Object.assign({}, state.channelRequests, {
[action.data.id]: { [action.data.id]: {
error : action.data.error, error : action.data.error,
channelData: {
name : action.data.name, name : action.data.name,
longId : action.data.longId, longId : action.data.longId,
shortId: action.data.shortId, shortId: action.data.shortId,
}, },
},
}), }),
}); });
// show a channel // show a channel
@ -134,8 +109,9 @@ export default function (state = initialState, action) {
return Object.assign({}, state, { return Object.assign({}, state, {
channelList: Object.assign({}, state.channelList, { channelList: Object.assign({}, state.channelList, {
[action.data.id]: { [action.data.id]: {
error : action.data.error, name : action.data.name,
channelData: action.data.channelData, longId : action.data.longId,
shortId : action.data.shortId,
claimsData: action.data.claimsData, claimsData: action.data.claimsData,
}, },
}), }),

View file

@ -26,7 +26,7 @@ function* newChannelRequest (action) {
({success, message, data} = yield call(getChannelData, name, channelId)); ({success, message, data} = yield call(getChannelData, name, channelId));
} catch (error) { } catch (error) {
// return yield put(addChannelRequest(id, error.message, null, null, null)); // return yield put(addChannelRequest(id, error.message, null, null, null));
return yield put(updateRequestError(message)); return yield put(updateRequestError(error.message));
} }
if (!success) { if (!success) {
// return yield put(addChannelRequest(id, message, null, null, null)); // return yield put(addChannelRequest(id, message, null, null, null));
@ -34,8 +34,7 @@ function* newChannelRequest (action) {
} }
const { longChannelClaimId: longId, shortChannelClaimId: shortId } = data; const { longChannelClaimId: longId, shortChannelClaimId: shortId } = data;
yield put(addChannelRequest(id, null, name, longId, shortId)); yield put(addChannelRequest(id, null, name, longId, shortId));
const channelData = {name, longId, shortId}; yield put(showNewChannel(name, shortId, longId));
yield put(showNewChannel(channelData));
} }
export function* watchNewAssetRequest () { export function* watchNewAssetRequest () {

View file

@ -1,6 +1,6 @@
import { call, put, takeLatest } from 'redux-saga/effects'; import { call, put, takeLatest } from 'redux-saga/effects';
import * as actions from 'constants/show_action_types'; 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'; import { getShortId, getClaimData } from 'api/assetApi';
function* getAssetDataAndShowAsset (action) { function* getAssetDataAndShowAsset (action) {
@ -10,10 +10,10 @@ function* getAssetDataAndShowAsset (action) {
try { try {
({success, message, data: shortId} = yield call(getShortId, name, claimId)); ({success, message, data: shortId} = yield call(getShortId, name, claimId));
} catch (error) { } catch (error) {
return yield put(updateShowAsset(error.message, null)); return yield put(updateRequestError(error.message));
} }
if (!success) { if (!success) {
return yield put(updateShowAsset(message, null)); return yield put(updateRequestError(message));
} }
// if no error, get claim data // if no error, get claim data
success = null; success = null;
@ -21,13 +21,13 @@ function* getAssetDataAndShowAsset (action) {
try { try {
({success, message, data: claimData} = yield call(getClaimData, name, claimId)); ({success, message, data: claimData} = yield call(getClaimData, name, claimId));
} catch (error) { } catch (error) {
return yield put(updateShowAsset(error.message, null)); return yield put(updateRequestError(error.message));
} }
if (!success) { if (!success) {
return yield put(updateShowAsset(message, null)); return yield put(updateRequestError(message));
} }
yield put(upsertAssetToAssetList(id, null, name, claimId, shortId, claimData)); yield put(addAssetToAssetList(id, null, name, claimId, shortId, claimData));
yield put(updateShowAsset(null, id)); yield put(updateRequestError(null));
} }
export function* watchShowNewAsset () { export function* watchShowNewAsset () {

View file

@ -1,22 +1,22 @@
import { call, put, takeLatest } from 'redux-saga/effects'; import { call, put, takeLatest } from 'redux-saga/effects';
import * as actions from 'constants/show_action_types'; 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'; import { getChannelClaims } from 'api/channelApi';
function* getChannelClaimsAndShowChannel (action) { 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; let success, message, claimsData;
try { try {
({ success, message, data: claimsData } = yield call(getChannelClaims, name, longId, 1)); ({ success, message, data: claimsData } = yield call(getChannelClaims, name, longId, 1));
} catch (error) { } catch (error) {
return yield put(updateShowChannel(error.message, null)); return yield put(updateRequestError(error.message));
} }
if (!success) { if (!success) {
return yield put(updateShowChannel(message, null)); return yield put(updateRequestError(message));
} }
const channelData = {name, shortId, longId}; yield put(addNewChannelToChannelList(id, name, shortId, longId, claimsData));
yield put(addNewChannelToChannelList(id, null, channelData, claimsData)); yield put(updateRequestError(null));
yield put(updateShowChannel(null, id));
} }
export function* watchShowNewChannel () { export function* watchShowNewChannel () {
@ -24,17 +24,17 @@ export function* watchShowNewChannel () {
}; };
function* getNewClaimsAndUpdateClaimsList (action) { function* getNewClaimsAndUpdateClaimsList (action) {
const { channelListId, name, longId, page } = action.data; const { channelKey, name, longId, page } = action.data;
let success, message, claimsData; let success, message, claimsData;
try { try {
({ success, message, data: claimsData } = yield call(getChannelClaims, name, longId, page)); ({ success, message, data: claimsData } = yield call(getChannelClaims, name, longId, page));
} catch (error) { } catch (error) {
return yield put(updateShowChannel(error.message, null)); return yield put(updateRequestError(error.message));
} }
if (!success) { 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 () { export function* watchShowNewChannelClaimsRequest () {