moved request error out of show page state
This commit is contained in:
parent
2744045c5c
commit
ffb4466fcf
9 changed files with 92 additions and 73 deletions
|
@ -1,5 +1,12 @@
|
||||||
import * as actions from 'constants/show_action_types';
|
import * as actions from 'constants/show_action_types';
|
||||||
|
|
||||||
|
export function updateRequestError (error) {
|
||||||
|
return {
|
||||||
|
type: actions.REQUEST_ERROR_UPDATE,
|
||||||
|
data: error,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function updateRequestWithChannelRequest (name, id) {
|
export function updateRequestWithChannelRequest (name, id) {
|
||||||
return {
|
return {
|
||||||
type: actions.REQUEST_CHANNEL_UPDATE,
|
type: actions.REQUEST_CHANNEL_UPDATE,
|
||||||
|
@ -27,12 +34,12 @@ export function updateRequestWithAssetRequest (name, id, channelName, channelId,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function updateRequestError (error) {
|
export function updateShowChannelError (error) {
|
||||||
return {
|
return {
|
||||||
type: actions.REQUEST_ERROR_UPDATE,
|
type: actions.SHOW_CHANNEL_ERROR,
|
||||||
data: error,
|
data: error,
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
export function updateChannelData (name, longId, shortId) {
|
export function updateChannelData (name, longId, shortId) {
|
||||||
return {
|
return {
|
||||||
|
@ -57,6 +64,13 @@ export function updateChannelClaimsData (claims, currentPage, totalPages, totalC
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function updateShowAssetError (error) {
|
||||||
|
return {
|
||||||
|
type: actions.SHOW_ASSET_ERROR,
|
||||||
|
data: error,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export function updateAssetClaimData (data, shortId) {
|
export function updateAssetClaimData (data, shortId) {
|
||||||
return {
|
return {
|
||||||
type: actions.ASSET_CLAIM_DATA_UPDATE,
|
type: actions.ASSET_CLAIM_DATA_UPDATE,
|
||||||
|
@ -84,13 +98,6 @@ export function updateFileAvailability (status) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function updateShowAssetError (error) {
|
|
||||||
return {
|
|
||||||
type: actions.SHOW_ASSET_ERROR,
|
|
||||||
data: error,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export function updateDisplayAssetError (error) {
|
export function updateDisplayAssetError (error) {
|
||||||
return {
|
return {
|
||||||
type: actions.DISPLAY_ASSET_ERROR,
|
type: actions.DISPLAY_ASSET_ERROR,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
import NavBar from 'containers/NavBar';
|
import NavBar from 'containers/NavBar';
|
||||||
|
|
||||||
class ErrorPage extends React.Component {
|
class ErrorPage extends React.Component {
|
||||||
|
@ -15,7 +16,8 @@ class ErrorPage extends React.Component {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// required props
|
ErrorPage.propTypes = {
|
||||||
// error
|
error: PropTypes.string.isRequired,
|
||||||
|
}
|
||||||
|
|
||||||
export default ErrorPage;
|
export default ErrorPage;
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
export const REQUEST_CHANNEL_UPDATE = 'REQUEST_CHANNEL_UPDATE';
|
export const REQUEST_CHANNEL_UPDATE = 'REQUEST_CHANNEL_UPDATE';
|
||||||
export const REQUEST_CLAIM_UPDATE = 'REQUEST_CLAIM_UPDATE';
|
export const REQUEST_CLAIM_UPDATE = 'REQUEST_CLAIM_UPDATE';
|
||||||
export const REQUEST_ERROR_UPDATE = 'REQUEST_ERROR_UPDATE';
|
export const REQUEST_ERROR_UPDATE = 'REQUEST_ERROR_UPDATE';
|
||||||
|
|
||||||
|
export const SHOW_CHANNEL_ERROR = 'SHOW_CHANNEL_ERROR';
|
||||||
export const CHANNEL_DATA_UPDATE = 'CHANNEL_DATA_UPDATE';
|
export const CHANNEL_DATA_UPDATE = 'CHANNEL_DATA_UPDATE';
|
||||||
export const CHANNEL_CLAIMS_DATA_UPDATE = 'CHANNEL_CLAIMS_DATA_UPDATE';
|
export const CHANNEL_CLAIMS_DATA_UPDATE = 'CHANNEL_CLAIMS_DATA_UPDATE';
|
||||||
|
|
||||||
|
export const SHOW_ASSET_ERROR = 'SHOW_ASSET_ERROR';
|
||||||
export const ASSET_CLAIM_DATA_UPDATE = 'ASSET_CLAIM_DATA_UPDATE';
|
export const ASSET_CLAIM_DATA_UPDATE = 'ASSET_CLAIM_DATA_UPDATE';
|
||||||
|
|
||||||
export const FILE_REQUESTED = 'FILE_REQUESTED';
|
export const FILE_REQUESTED = 'FILE_REQUESTED';
|
||||||
export const FILE_AVAILABILITY_UPDATE = 'FILE_AVAILABILITY_UPDATE';
|
export const FILE_AVAILABILITY_UPDATE = 'FILE_AVAILABILITY_UPDATE';
|
||||||
export const SHOW_ASSET_ERROR = 'SHOW_ASSET_ERROR';
|
|
||||||
export const DISPLAY_ASSET_ERROR = 'DISPLAY_ASSET_ERROR';
|
export const DISPLAY_ASSET_ERROR = 'DISPLAY_ASSET_ERROR';
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import ErrorPage from 'components/ErrorPage';
|
||||||
import ShowAssetLite from 'components/ShowAssetLite';
|
import ShowAssetLite from 'components/ShowAssetLite';
|
||||||
import ShowAssetDetails from 'components/ShowAssetDetails';
|
import ShowAssetDetails from 'components/ShowAssetDetails';
|
||||||
import request from 'utils/request';
|
import request from 'utils/request';
|
||||||
|
@ -43,7 +44,6 @@ class ShowAsset extends React.Component {
|
||||||
}
|
}
|
||||||
getLongClaimId (params) {
|
getLongClaimId (params) {
|
||||||
const url = `/api/claim/long-id`;
|
const url = `/api/claim/long-id`;
|
||||||
console.log('params:', params);
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
request(url, params)
|
request(url, params)
|
||||||
.then(({ success, message, data }) => {
|
.then(({ success, message, data }) => {
|
||||||
|
@ -97,7 +97,7 @@ class ShowAsset extends React.Component {
|
||||||
const { error, claimData, extension } = this.props;
|
const { error, claimData, extension } = this.props;
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
<p>{error}</p>
|
<ErrorPage error={error}/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (claimData) {
|
if (claimData) {
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import {updateChannelData} from 'actions/show';
|
import {updateChannelData, updateShowChannelError} from 'actions/show';
|
||||||
import View from './view';
|
import View from './view';
|
||||||
|
|
||||||
const mapStateToProps = ({ show }) => {
|
const mapStateToProps = ({ show }) => {
|
||||||
return {
|
return {
|
||||||
requestName: show.channelRequest.name,
|
requestName: show.channelRequest.name,
|
||||||
requestId : show.channelRequest.id,
|
requestId : show.channelRequest.id,
|
||||||
|
error : show.showChannel.error,
|
||||||
name : show.showChannel.channelData.name,
|
name : show.showChannel.channelData.name,
|
||||||
shortId : show.showChannel.channelData.shortId,
|
shortId : show.showChannel.channelData.shortId,
|
||||||
longId : show.showChannel.channelData.longId,
|
longId : show.showChannel.channelData.longId,
|
||||||
|
@ -14,8 +15,12 @@ const mapStateToProps = ({ show }) => {
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => {
|
const mapDispatchToProps = dispatch => {
|
||||||
return {
|
return {
|
||||||
|
onShowChannelError: (error) => {
|
||||||
|
dispatch(updateShowChannelError(error));
|
||||||
|
},
|
||||||
onChannelDataUpdate: (name, longId, shortId) => {
|
onChannelDataUpdate: (name, longId, shortId) => {
|
||||||
dispatch(updateChannelData(name, longId, shortId));
|
dispatch(updateChannelData(name, longId, shortId));
|
||||||
|
dispatch(updateShowChannelError(null)); // clear any errors
|
||||||
},
|
},
|
||||||
onChannelDataClear: () => {
|
onChannelDataClear: () => {
|
||||||
dispatch(updateChannelData(null, null, null));
|
dispatch(updateChannelData(null, null, null));
|
||||||
|
|
|
@ -1,15 +1,10 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import ErrorPage from 'components/ErrorPage';
|
||||||
import NavBar from 'containers/NavBar';
|
import NavBar from 'containers/NavBar';
|
||||||
import ChannelClaimsDisplay from 'containers/ChannelClaimsDisplay';
|
import ChannelClaimsDisplay from 'containers/ChannelClaimsDisplay';
|
||||||
import request from 'utils/request';
|
import request from 'utils/request';
|
||||||
|
|
||||||
class ShowChannel extends React.Component {
|
class ShowChannel extends React.Component {
|
||||||
constructor (props) {
|
|
||||||
super(props);
|
|
||||||
this.state = {
|
|
||||||
error: null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
this.getAndStoreChannelData(this.props.requestName, this.props.requestId);
|
this.getAndStoreChannelData(this.props.requestName, this.props.requestId);
|
||||||
}
|
}
|
||||||
|
@ -23,42 +18,39 @@ class ShowChannel extends React.Component {
|
||||||
const url = `/api/channel/data/${name}/${id}`;
|
const url = `/api/channel/data/${name}/${id}`;
|
||||||
return request(url)
|
return request(url)
|
||||||
.then(({ success, message, data }) => {
|
.then(({ success, message, data }) => {
|
||||||
console.log('api/channel-data response:', data);
|
console.log('api/channel/data/ response:', data);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
return this.setState({error: message});
|
return this.props.onShowChannelError(message);
|
||||||
}
|
}
|
||||||
this.setState({error: null}); // note: store this error at app level also
|
|
||||||
this.props.onChannelDataUpdate(data.channelName, data.longChannelClaimId, data.shortChannelClaimId);
|
this.props.onChannelDataUpdate(data.channelName, data.longChannelClaimId, data.shortChannelClaimId);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.setState({error: error.message});
|
return this.props.onShowChannelError(error.message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
componentWillUnmount () {
|
componentWillUnmount () {
|
||||||
this.props.onChannelDataClear();
|
this.props.onChannelDataClear();
|
||||||
}
|
}
|
||||||
render () {
|
render () {
|
||||||
|
const { error, name, longId, shortId } = this.props;
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<ErrorPage error={error}/>
|
||||||
|
);
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<NavBar/>
|
<NavBar/>
|
||||||
{this.state.error ? (
|
<div className="row row--tall row--padded">
|
||||||
<div className="row row--tall row--padded">
|
<div className="column column--10">
|
||||||
<div className="column column--10">
|
<h2>channel name: {name ? name : 'loading...'}</h2>
|
||||||
<p>{this.state.error}</p>
|
<p className={'fine-print'}>full channel id: {longId ? longId : 'loading...'}</p>
|
||||||
</div>
|
<p className={'fine-print'}>short channel id: {shortId ? shortId : 'loading...'}</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
<div className="column column--10">
|
||||||
<div className="row row--tall row--padded">
|
{(name && longId) && <ChannelClaimsDisplay />}
|
||||||
<div className="column column--10">
|
|
||||||
<h2>channel name: {this.props.name ? this.props.name : 'loading...'}</h2>
|
|
||||||
<p className={'fine-print'}>full channel id: {this.props.longId ? this.props.longId : 'loading...'}</p>
|
|
||||||
<p className={'fine-print'}>short channel id: {this.props.shortId ? this.props.shortId : 'loading...'}</p>
|
|
||||||
</div>
|
|
||||||
<div className="column column--10">
|
|
||||||
{(this.props.name && this.props.longId) && <ChannelClaimsDisplay />}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { updateRequestWithChannelRequest, updateRequestWithAssetRequest } from 'actions/show';
|
import { updateRequestError, updateRequestWithChannelRequest, updateRequestWithAssetRequest } from 'actions/show';
|
||||||
import View from './view';
|
import View from './view';
|
||||||
|
|
||||||
const mapStateToProps = ({ show }) => {
|
const mapStateToProps = ({ show }) => {
|
||||||
return {
|
return {
|
||||||
|
error : show.request.error,
|
||||||
requestType: show.request.type,
|
requestType: show.request.type,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapDispatchToProps = dispatch => {
|
const mapDispatchToProps = dispatch => {
|
||||||
return {
|
return {
|
||||||
|
onRequestError: (error) => {
|
||||||
|
dispatch(updateRequestError(error));
|
||||||
|
},
|
||||||
onChannelRequest: (name, id) => {
|
onChannelRequest: (name, id) => {
|
||||||
dispatch(updateRequestWithChannelRequest(name, id));
|
dispatch(updateRequestWithChannelRequest(name, id));
|
||||||
},
|
},
|
||||||
|
|
|
@ -9,24 +9,17 @@ import { CHANNEL, ASSET } from 'constants/show_request_types';
|
||||||
class ShowPage extends React.Component {
|
class ShowPage extends React.Component {
|
||||||
constructor (props) {
|
constructor (props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
|
||||||
error: null,
|
|
||||||
};
|
|
||||||
this.parseUrlAndUpdateState = this.parseUrlAndUpdateState.bind(this);
|
this.parseUrlAndUpdateState = this.parseUrlAndUpdateState.bind(this);
|
||||||
this.parseAndUpdateIdentifierAndClaim = this.parseAndUpdateIdentifierAndClaim.bind(this);
|
this.parseAndUpdateIdentifierAndClaim = this.parseAndUpdateIdentifierAndClaim.bind(this);
|
||||||
this.parseAndUpdateClaimOnly = this.parseAndUpdateClaimOnly.bind(this);
|
this.parseAndUpdateClaimOnly = this.parseAndUpdateClaimOnly.bind(this);
|
||||||
}
|
}
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
console.log('ShowPage did mount');
|
const { identifier, claim } = this.props.match.params;
|
||||||
const identifier = this.props.match.params.identifier;
|
|
||||||
const claim = this.props.match.params.claim;
|
|
||||||
this.parseUrlAndUpdateState(identifier, claim);
|
this.parseUrlAndUpdateState(identifier, claim);
|
||||||
}
|
}
|
||||||
componentWillReceiveProps (nextProps) {
|
componentWillReceiveProps (nextProps) {
|
||||||
if (nextProps.match.params !== this.props.match.params) {
|
if (nextProps.match.params !== this.props.match.params) {
|
||||||
console.log('ShowPage received new params props');
|
const { identifier, claim } = nextProps.match.params;
|
||||||
const identifier = nextProps.match.params.identifier;
|
|
||||||
const claim = nextProps.match.params.claim;
|
|
||||||
this.parseUrlAndUpdateState(identifier, claim);
|
this.parseUrlAndUpdateState(identifier, claim);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +38,7 @@ class ShowPage extends React.Component {
|
||||||
({ isChannel, channelName, channelClaimId, claimId } = lbryUri.parseIdentifier(modifier));
|
({ isChannel, channelName, channelClaimId, claimId } = lbryUri.parseIdentifier(modifier));
|
||||||
({ claimName, extension } = lbryUri.parseClaim(claim));
|
({ claimName, extension } = lbryUri.parseClaim(claim));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return this.setState({error: error.message});
|
return this.props.onRequestError(error.message);
|
||||||
}
|
}
|
||||||
// update the store
|
// update the store
|
||||||
if (isChannel) {
|
if (isChannel) {
|
||||||
|
@ -61,7 +54,7 @@ class ShowPage extends React.Component {
|
||||||
try {
|
try {
|
||||||
({ isChannel, channelName, channelClaimId } = lbryUri.parseIdentifier(claim));
|
({ isChannel, channelName, channelClaimId } = lbryUri.parseIdentifier(claim));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return this.setState({error: error.message});
|
return this.props.onRequestError(error.message);
|
||||||
}
|
}
|
||||||
// return early if this request is for a channel
|
// return early if this request is for a channel
|
||||||
if (isChannel) {
|
if (isChannel) {
|
||||||
|
@ -72,19 +65,18 @@ class ShowPage extends React.Component {
|
||||||
try {
|
try {
|
||||||
({claimName, extension} = lbryUri.parseClaim(claim));
|
({claimName, extension} = lbryUri.parseClaim(claim));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return this.setState({error: error.message});
|
return this.props.onRequestError(error.message);
|
||||||
}
|
}
|
||||||
this.props.onAssetRequest(claimName, null, null, null, extension);
|
this.props.onAssetRequest(claimName, null, null, null, extension);
|
||||||
}
|
}
|
||||||
render () {
|
render () {
|
||||||
console.log('rendering ShowPage');
|
const { error, requestType } = this.props;
|
||||||
console.log('ShowPage props', this.props);
|
if (error) {
|
||||||
if (this.state.error) {
|
|
||||||
return (
|
return (
|
||||||
<ErrorPage error={this.state.error}/>
|
<ErrorPage error={error}/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
switch (this.props.requestType) {
|
switch (requestType) {
|
||||||
case CHANNEL:
|
case CHANNEL:
|
||||||
return <ShowChannel />;
|
return <ShowChannel />;
|
||||||
case ASSET:
|
case ASSET:
|
||||||
|
|
|
@ -23,6 +23,7 @@ const initialState = {
|
||||||
extension: null,
|
extension: null,
|
||||||
},
|
},
|
||||||
showChannel: {
|
showChannel: {
|
||||||
|
error : null,
|
||||||
channelData: {
|
channelData: {
|
||||||
name : null,
|
name : null,
|
||||||
shortId: null,
|
shortId: null,
|
||||||
|
@ -52,23 +53,33 @@ Reducers describe how the application's state changes in response to actions
|
||||||
|
|
||||||
export default function (state = initialState, action) {
|
export default function (state = initialState, action) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case actions.REQUEST_CHANNEL_UPDATE:
|
// request cases
|
||||||
|
case actions.REQUEST_ERROR_UPDATE:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
request: Object.assign({}, state.request, {
|
request: Object.assign({}, state.request, {
|
||||||
type: CHANNEL,
|
error: action.data,
|
||||||
}),
|
}),
|
||||||
|
});
|
||||||
|
case actions.REQUEST_CHANNEL_UPDATE:
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
request: {
|
||||||
|
type : CHANNEL,
|
||||||
|
error: null,
|
||||||
|
},
|
||||||
channelRequest: action.data,
|
channelRequest: action.data,
|
||||||
});
|
});
|
||||||
case actions.REQUEST_CLAIM_UPDATE:
|
case actions.REQUEST_CLAIM_UPDATE:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
request: Object.assign({}, state.request, {
|
request: {
|
||||||
type: ASSET,
|
type : ASSET,
|
||||||
}),
|
error: null,
|
||||||
|
},
|
||||||
assetRequest: action.data,
|
assetRequest: action.data,
|
||||||
});
|
});
|
||||||
case actions.REQUEST_ERROR_UPDATE:
|
// show channel cases
|
||||||
|
case actions.SHOW_CHANNEL_ERROR:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
request: Object.assign({}, state.request, {
|
showChannel: Object.assign({}, state.showAsset, {
|
||||||
error: action.data,
|
error: action.data,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
@ -84,6 +95,13 @@ export default function (state = initialState, action) {
|
||||||
channelClaimsData: action.data,
|
channelClaimsData: action.data,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
// show asset cases
|
||||||
|
case actions.SHOW_ASSET_ERROR:
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
showAsset: Object.assign({}, state.showAsset, {
|
||||||
|
error: action.data,
|
||||||
|
}),
|
||||||
|
});
|
||||||
case actions.ASSET_CLAIM_DATA_UPDATE:
|
case actions.ASSET_CLAIM_DATA_UPDATE:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
showAsset: Object.assign({}, state.showAsset, {
|
showAsset: Object.assign({}, state.showAsset, {
|
||||||
|
@ -91,12 +109,7 @@ export default function (state = initialState, action) {
|
||||||
shortId : action.data.shortId,
|
shortId : action.data.shortId,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
case actions.SHOW_ASSET_ERROR:
|
// display asset cases
|
||||||
return Object.assign({}, state, {
|
|
||||||
showAsset: Object.assign({}, state.showAsset, {
|
|
||||||
error: action.data,
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
case actions.FILE_AVAILABILITY_UPDATE:
|
case actions.FILE_AVAILABILITY_UPDATE:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
displayAsset: Object.assign({}, state.displayAsset, {
|
displayAsset: Object.assign({}, state.displayAsset, {
|
||||||
|
|
Loading…
Reference in a new issue