converted channel display to use id

This commit is contained in:
bill bittner 2018-02-08 16:42:13 -08:00
parent c96c4d1fbd
commit 75b5981e01
8 changed files with 43 additions and 68 deletions

View file

@ -109,10 +109,10 @@ export function showNewChannel (channelData) {
}; };
}; };
export function updateShowChannel (error, name, shortId, longId, claimsData) { export function updateShowChannel (error, id) {
return { return {
type: actions.SHOW_CHANNEL_UPDATE, type: actions.SHOW_CHANNEL_UPDATE,
data: { error, name, shortId, longId, claimsData }, data: { error, id },
}; };
}; };

View file

@ -2,15 +2,9 @@ import { connect } from 'react-redux';
import { } from 'actions/show'; import { } from 'actions/show';
import View from './view'; import View from './view';
const mapStateToProps = ({ show : { showChannel: { error, channelData, claimsData } } }) => { const mapStateToProps = ({ show }) => {
return { return {
error : error, channel: show.channelList[show.showChannel.id],
name : channelData.name,
longId : channelData.longId,
claims : claimsData.claims,
currentPage: claimsData.currentPage,
totalPages : claimsData.totalPages,
totalClaims: claimsData.totalClaims,
}; };
}; };

View file

@ -20,7 +20,7 @@ class ChannelClaimsDisplay extends React.Component {
this.showNewPage(nextPage); this.showNewPage(nextPage);
} }
render () { render () {
const { error, claims, currentPage, totalPages } = this.props; const { channel: { error, claimsData: { claims, currentPage, totalPages } } } = this.props;
return ( return (
<div> <div>
{error ? ( {error ? (

View file

@ -13,25 +13,26 @@ const mapStateToProps = ({ show }) => {
channelList : show.channelList, channelList : show.channelList,
// show channel // show channel
error : show.showChannel.error, error : show.showChannel.error,
name : show.showChannel.channelData.name, id : show.showChannel.id,
shortId : show.showChannel.channelData.shortId, channel : show.channelList[show.showChannel.id],
longId : show.showChannel.channelData.longId,
}; };
}; };
const mapDispatchToProps = dispatch => { const mapDispatchToProps = dispatch => {
return { return {
// request
onNewChannelRequest (id, name, channelId) { onNewChannelRequest (id, name, channelId) {
dispatch(newChannelRequest(id, name, channelId)); dispatch(newChannelRequest(id, name, channelId));
}, },
onRequestError: (error) => { onRequestError: (error) => {
dispatch(updateRequestError(error, null, null)); dispatch(updateRequestError(error, null, null));
}, },
// show channel
onShowNewChannel: (channelData) => { onShowNewChannel: (channelData) => {
dispatch(showNewChannel(channelData)); dispatch(showNewChannel(channelData));
}, },
onShowExistingChannel: (error, name, shortId, longId, claimsData) => { onShowExistingChannel: (id) => {
dispatch(updateShowChannel(error, name, shortId, longId, claimsData)); dispatch(updateShowChannel(null, id));
}, },
onShowChannelClear: () => { onShowChannelClear: () => {
dispatch(clearShowChannel()); dispatch(clearShowChannel());

View file

@ -49,7 +49,7 @@ class ShowChannel extends React.Component {
const channelRecordId = `c#${channelData.name}#${channelData.longId}`; const channelRecordId = `c#${channelData.name}#${channelData.longId}`;
const existingChannel = channelList[channelRecordId]; const existingChannel = channelList[channelRecordId];
if (existingChannel) { if (existingChannel) {
this.showExistingChannel(existingChannel); this.showExistingChannel(channelRecordId);
} else { } else {
this.showNewChannel(channelData); this.showNewChannel(channelData);
} }
@ -57,34 +57,39 @@ class ShowChannel extends React.Component {
showNewChannel (channelData) { showNewChannel (channelData) {
this.props.onShowNewChannel(channelData); this.props.onShowNewChannel(channelData);
}; };
showExistingChannel (existingChannel) { showExistingChannel (channelRecordId) {
const { error, channelData: {name, shortId, longId}, claimsData } = existingChannel; this.props.onShowExistingChannel(channelRecordId);
this.props.onShowExistingChannel(error, name, shortId, longId, claimsData);
}; };
componentWillUnmount () { componentWillUnmount () {
this.props.onShowChannelClear(); this.props.onShowChannelClear();
} }
render () { render () {
const { error, name, longId, shortId } = this.props; const { error, channel } = this.props;
if (error) { if (error) {
return ( return (
<ErrorPage error={error}/> <ErrorPage error={error}/>
); );
}; };
return ( if (channel) {
<div> const { channelData: { name, longId, shortId } } = channel;
<NavBar/> return (
<div className="row row--tall row--padded"> <div>
<div className="column column--10"> <NavBar/>
<h2>channel name: {name ? name : 'loading...'}</h2> <div className="row row--tall row--padded">
<p className={'fine-print'}>full channel id: {longId ? longId : 'loading...'}</p> <div className="column column--10">
<p className={'fine-print'}>short channel id: {shortId ? shortId : 'loading...'}</p> <h2>channel name: {name ? name : 'loading...'}</h2>
</div> <p className={'fine-print'}>full channel id: {longId ? longId : 'loading...'}</p>
<div className="column column--10"> <p className={'fine-print'}>short channel id: {shortId ? shortId : 'loading...'}</p>
{(name && longId) && <ChannelClaimsDisplay />} </div>
<div className="column column--10">
{(name && longId) && <ChannelClaimsDisplay />}
</div>
</div> </div>
</div> </div>
</div> );
};
return (
<ErrorPage error={'loading channel data...'}/>
); );
} }
}; };

View file

@ -10,18 +10,8 @@ const initialState = {
requestId: null, requestId: null,
}, },
showChannel: { showChannel: {
error : null, error: null,
channelData: { id : null,
name : null,
shortId: null,
longId : null,
},
claimsData: {
claims : null,
currentPage: null,
totalPages : null,
totalClaims: null,
},
}, },
showAsset: { showAsset: {
error: null, error: null,
@ -132,30 +122,15 @@ export default function (state = initialState, action) {
case actions.SHOW_CHANNEL_UPDATE: case actions.SHOW_CHANNEL_UPDATE:
return Object.assign({}, state, { return Object.assign({}, state, {
showChannel: { showChannel: {
error : action.data.error, error: action.data.error,
channelData: { id : action.data.id,
name : action.data.name,
shortId: action.data.shortId,
longId : action.data.longId,
},
claimsData: action.data.claimsData,
}, },
}); });
case actions.SHOW_CHANNEL_CLEAR: case actions.SHOW_CHANNEL_CLEAR:
return Object.assign({}, state, { return Object.assign({}, state, {
showChannel: { showChannel: {
error : null, error: null,
channelData: { id : null,
name : null,
shortId: null,
longId : null,
},
claimsData: {
claims : null,
currentPage: null,
totalPages : null,
totalClaims: null,
},
}, },
}); });
// add channel to channel list // add channel to channel list

View file

@ -26,8 +26,8 @@ function* getAssetDataAndShowAsset (action) {
if (!success) { if (!success) {
return yield put(updateShowAsset(message, null)); return yield put(updateShowAsset(message, null));
} }
yield put(updateShowAsset(null, id));
yield put(upsertAssetToAssetList(id, null, name, claimId, shortId, claimData)); yield put(upsertAssetToAssetList(id, null, name, claimId, shortId, claimData));
yield put(updateShowAsset(null, id));
} }
export function* watchShowNewAsset () { export function* watchShowNewAsset () {

View file

@ -9,14 +9,14 @@ function* getNewChannelDataAndShowChannel (action) {
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, name, shortId, longId)); return yield put(updateShowChannel(error.message, null));
} }
if (!success) { if (!success) {
return yield put(updateShowChannel(message, name, shortId, longId)); return yield put(updateShowChannel(message, null));
} }
yield put(updateShowChannel(null, name, shortId, longId, claimsData));
const channelData = {name, shortId, longId}; const channelData = {name, shortId, longId};
yield put(addNewChannelToChannelList(id, null, channelData, claimsData)); yield put(addNewChannelToChannelList(id, null, channelData, claimsData));
yield put(updateShowChannel(null, id));
} }
export function* watchShowNewChannel () { export function* watchShowNewChannel () {