switched show and channel components back to inernal state

This commit is contained in:
bill bittner 2018-02-02 12:46:18 -08:00
parent 1cbe9edf21
commit 7600ff5c54
14 changed files with 147 additions and 219 deletions

View file

@ -5,25 +5,25 @@ module.exports = {
let status, message; let status, message;
// check for daemon being turned off // check for daemon being turned off
if (error.code === 'ECONNREFUSED') { if (error.code === 'ECONNREFUSED') {
status = 503; status = 200;
message = 'Connection refused. The daemon may not be running.'; message = 'Connection refused. The daemon may not be running.';
// check for errors from the daemon // // check for errors from the daemon
} else if (error.response) { // } else if (error.response) {
status = error.response.status || 500; // status = error.response.status || 500;
if (error.response.data) { // if (error.response.data) {
if (error.response.data.message) { // if (error.response.data.message) {
message = error.response.data.message; // message = error.response.data.message;
} else if (error.response.data.error) { // } else if (error.response.data.error) {
message = error.response.data.error.message; // message = error.response.data.error.message;
} else { // } else {
message = error.response.data; // message = error.response.data;
} // }
} else { // } else {
message = error.response; // message = error.response;
} // }
// check for thrown errors // check for thrown errors
} else if (error.message) { } else if (error.message) {
status = 400; status = 200;
message = error.message; message = error.message;
// fallback for everything else // fallback for everything else
} else { } else {

View file

@ -10,13 +10,13 @@ function handleLbrynetResponse ({ data }, resolve, reject) {
// check for an error // check for an error
if (data.result.error) { if (data.result.error) {
logger.debug('Lbrynet api error:', data.result.error); logger.debug('Lbrynet api error:', data.result.error);
reject(data.result.error); reject(new Error(data.result.error));
return; return;
}; };
resolve(data.result); resolve(data.result);
return; return;
} }
// fallback in case the just timed out // fallback in case it just timed out
reject(JSON.stringify(data)); reject(JSON.stringify(data));
} }

View file

@ -19,29 +19,3 @@ export function updateRequestWithAssetRequest (name, id, channelName, channelId,
extension, extension,
}; };
}; };
export function updateChannelData (name, longId, shortId) {
return {
type: actions.CHANNEL_DATA_UPDATE,
name,
longId,
shortId,
};
};
export function updateChannelClaimsData (claims, currentPage, totalPages, totalClaims) {
return {
type: actions.CHANNEL_CLAIMS_DATA_UPDATE,
claims,
currentPage,
totalPages,
totalClaims,
};
};
export function updateAssetData (data) {
return {
type: actions.ASSET_DATA_UPDATE,
data,
};
};

View file

@ -39,9 +39,12 @@ class AssetDisplay extends React.Component {
const url = `/api/file-is-available/${this.props.name}/${this.props.claimId}`; const url = `/api/file-is-available/${this.props.name}/${this.props.claimId}`;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
Request(url) Request(url)
.then(isAvailable => { .then(({success, message, data: isAvailable}) => {
console.log('/api/file-is-available response:', isAvailable); if (success) {
resolve(isAvailable); console.log('/api/file-is-available response:', isAvailable);
return resolve(isAvailable);
}
reject(new Error(message));
}) })
.catch(error => { .catch(error => {
reject(error); reject(error);
@ -53,9 +56,12 @@ class AssetDisplay extends React.Component {
const url = `/api/claim-get/${this.props.name}/${this.props.claimId}`; const url = `/api/claim-get/${this.props.name}/${this.props.claimId}`;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
Request(url) Request(url)
.then(response => { .then(({success, message}) => {
console.log('/api/claim-get response:', response); console.log('/api/claim-get response:', success, message);
resolve(true); if (success) {
return resolve(true);
}
reject(new Error(message));
}) })
.catch(error => { .catch(error => {
reject(error); reject(error);
@ -65,6 +71,11 @@ class AssetDisplay extends React.Component {
render () { render () {
return ( return (
<div id="asset-display-component"> <div id="asset-display-component">
{(this.state.status === LOCAL_CHECK) &&
<div>
<p>Checking to see if Spee.ch has your asset locally...</p>
</div>
}
{(this.state.status === SEARCHING) && {(this.state.status === SEARCHING) &&
<div> <div>
<p>Sit tight, we're searching the LBRY blockchain for your asset!</p> <p>Sit tight, we're searching the LBRY blockchain for your asset!</p>

View file

@ -0,0 +1,79 @@
import React from 'react/index';
import AssetPreview from 'components/AssetPreview';
import request from 'utils/request';
class ChannelClaimsDisplay extends React.Component {
constructor (props) {
super(props);
this.state = {
error : null,
claims : null,
currentPage: null,
totalPages : null,
totalClaims: null,
};
this.updateClaimsData = this.updateClaimsData.bind(this);
}
componentDidMount () {
this.updateClaimsData(1);
}
updateClaimsData (page) {
const name = this.props.name;
const longId = this.props.longId;
const url = `/api/channel-claims/${name}/${longId}/${page}`;
const that = this;
return request(url)
.then(({ success, message, data }) => {
console.log('api/channel-claims response:', data);
if (!success) {
return that.setState({error: message});
}
this.setState({
claims : data.claims,
currentPage: data.currentPage,
totalPages : data.totalPages,
totalClaims: data.totalResults,
});
})
.catch((error) => {
that.setState({error: error.message});
});
}
render () {
return (
<div>
{this.state.error ? (
<div className="row">
<div className="column column--10">
<p>{this.state.error}</p>
</div>
</div>
) : (
<div className="row row--tall">
<p>total pages: {this.state.totalPages}</p>
<p>total claims: {this.state.totalClaims}</p>
{this.state.claims &&
<div>
{this.state.claims.map((claim, index) => <AssetPreview
name={claim.name}
claimId={claim.claimId}
contentType={claim.contentType}
key={index}
/>)}
{(this.state.currentPage > 1) && <button onClick={this.updateClaimsData(this.state.currentPage - 1)}>Previous Page</button>}
<p>current page: {this.state.currentPage}</p>
{(this.state.currentPage < this.state.totalPages) && <button onClick={this.updateClaimsData(this.state.currentPage + 1)}>Next Page</button>}
</div>
}
</div>
)}
</div>
);
}
};
// PropTypes
// name
// id
export default ChannelClaimsDisplay;

View file

@ -1,5 +1,2 @@
export const REQUEST_UPDATE_CHANNEL = 'REQUEST_UPDATE_CHANNEL'; export const REQUEST_UPDATE_CHANNEL = 'REQUEST_UPDATE_CHANNEL';
export const REQUEST_UPDATE_CLAIM = 'REQUEST_UPDATE_CLAIM'; export const REQUEST_UPDATE_CLAIM = 'REQUEST_UPDATE_CLAIM';
export const CHANNEL_DATA_UPDATE = 'CHANNEL_DATA_UPDATE';
export const CHANNEL_CLAIMS_DATA_UPDATE = 'CHANNEL_CLAIMS_DATA_UPDATE';
export const ASSET_DATA_UPDATE = 'ASSET_DATA_UPDATE';

View file

@ -1,24 +0,0 @@
import { connect } from 'react-redux';
import View from './view';
import {updateChannelClaimsData} from 'actions/show';
const mapStateToProps = ({ show }) => {
return {
name : show.channelData.name,
longId : show.channelData.longId,
claims : show.channelClaimsData.claims,
currentPage: show.channelClaimsData.currentPage,
totalPages : show.channelClaimsData.totalPages,
totalClaims: show.channelClaimsData.totalClaims,
};
};
const mapDispatchToProps = dispatch => {
return {
onClaimsDataChange: (claims, currentPage, totalPages, totalClaims) => {
dispatch(updateChannelClaimsData(claims, currentPage, totalPages, totalClaims));
},
};
};
export default connect(mapStateToProps, mapDispatchToProps)(View);

View file

@ -1,63 +0,0 @@
import React from 'react';
import AssetPreview from 'components/AssetPreview/index';
import request from 'utils/request';
class ChannelClaimsDisplay extends React.Component {
constructor (props) {
super(props);
this.state = {
error: null,
};
this.getAndStoreChannelClaims = this.getAndStoreChannelClaims.bind(this);
}
componentDidMount () {
this.getAndStoreChannelClaims(this.props.name, this.props.longId, this.props.currentPage);
}
getAndStoreChannelClaims (name, id, page) {
if (!id) id = 'none';
const url = `/api/channel-claims/${name}/${id}/${page}`;
const that = this;
return request(url)
.then(({ success, message, data }) => {
console.log('api/channel-claims response:', data);
if (!success) {
return that.setState({error: message});
}
this.props.onClaimsDataChange(data.claims, data.currentPage, data.totalPages, data.totalResults);
})
.catch((error) => {
that.setState({error: error.message});
});
}
render () {
return (
<div>
{this.state.error ? (
<div className="row">
<div className="column column--10">
<p>{this.state.error}</p>
</div>
</div>
) : (
<div className="row row--tall">
{this.props.claims &&
<div>
{this.props.claims.map((claim, index) => <AssetPreview
name={claim.name}
claimId={claim.claimId}
contentType={claim.contentType}
key={index}
/>)}
<p>current page: {this.props.currentPage}</p>
<p>total pages: {this.props.totalPages}</p>
<p>total claims: {this.props.totalClaims}</p>
</div>
}
</div>
)}
</div>
);
}
};
export default ChannelClaimsDisplay;

View file

@ -1,5 +1,4 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { updateAssetData } from 'actions/show';
import View from './view'; import View from './view';
const mapStateToProps = ({ show }) => { const mapStateToProps = ({ show }) => {
@ -7,16 +6,7 @@ const mapStateToProps = ({ show }) => {
modifier : show.assetRequest.modifier, modifier : show.assetRequest.modifier,
claim : show.assetRequest.name, claim : show.assetRequest.name,
extension: show.assetRequest.extension, extension: show.assetRequest.extension,
claimData: show.assetData,
}; };
}; };
const mapDispatchToProps = dispatch => { export default connect(mapStateToProps, null)(View);
return {
onAssetDataUpdate: (data) => {
dispatch(updateAssetData(data));
},
};
};
export default connect(mapStateToProps, mapDispatchToProps)(View);

View file

@ -7,7 +7,8 @@ class ShowAsset extends React.Component {
constructor (props) { constructor (props) {
super(props); super(props);
this.state = { this.state = {
error: null, error : null,
claimData: null,
}; };
this.getLongClaimId = this.getLongClaimId.bind(this); this.getLongClaimId = this.getLongClaimId.bind(this);
this.getClaimData = this.getClaimData.bind(this); this.getClaimData = this.getClaimData.bind(this);
@ -42,7 +43,7 @@ class ShowAsset extends React.Component {
return that.getClaimData(name, claimLongId); return that.getClaimData(name, claimLongId);
}) })
.then(claimData => { .then(claimData => {
this.props.onAssetDataUpdate(claimData); this.setState({claimData});
}) })
.catch(error => { .catch(error => {
this.setState({error}); this.setState({error});
@ -86,14 +87,14 @@ class ShowAsset extends React.Component {
return ( return (
<ShowAssetLite <ShowAssetLite
error={this.state.error} error={this.state.error}
claimData={this.props.claimData} claimData={this.state.claimData}
/> />
); );
} }
return ( return (
<ShowAssetDetails <ShowAssetDetails
error={this.state.error} error={this.state.error}
claimData={this.props.claimData} claimData={this.state.claimData}
/> />
); );
} }

View file

@ -1,27 +1,11 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { updateChannelData } from 'actions/show';
import View from './view'; import View from './view';
const mapStateToProps = ({ show }) => { const mapStateToProps = ({ show }) => {
return { return {
request: { requestName: show.channelRequest.name,
name: show.channelRequest.name, requestId : show.channelRequest.id,
id : show.channelRequest.id,
},
channel: {
name : show.channelData.name,
shortId: show.channelData.shortId,
longId : show.channelData.longId,
},
}; };
}; };
const mapDispatchToProps = dispatch => { export default connect(mapStateToProps, null)(View);
return {
onChannelDataChange: (name, longId, shortId) => {
dispatch(updateChannelData(name, longId, shortId));
},
};
};
export default connect(mapStateToProps, mapDispatchToProps)(View);

View file

@ -1,18 +1,21 @@
import React from 'react'; import React from 'react';
import NavBar from 'containers/NavBar'; import NavBar from 'containers/NavBar';
import ChannelClaimsDisplay from 'containers/ChannelClaimsDisplay'; import ChannelClaimsDisplay from 'components/ChannelClaimsDisplay';
import request from 'utils/request'; import request from 'utils/request';
class ShowChannel extends React.Component { class ShowChannel extends React.Component {
constructor (props) { constructor (props) {
super(props); super(props);
this.state = { this.state = {
error: null, error : null,
name : null,
shortId: null,
longId : null,
}; };
this.getAndStoreChannelData = this.getAndStoreChannelData.bind(this); this.getAndStoreChannelData = this.getAndStoreChannelData.bind(this);
} }
componentDidMount () { componentDidMount () {
this.getAndStoreChannelData(this.props.request.name, this.props.request.id); this.getAndStoreChannelData(this.props.requestName, this.props.requestId);
} }
getAndStoreChannelData (name, id) { getAndStoreChannelData (name, id) {
if (!id) id = 'none'; if (!id) id = 'none';
@ -24,7 +27,11 @@ class ShowChannel extends React.Component {
if (!success) { if (!success) {
return that.setState({error: message}); return that.setState({error: message});
} }
this.props.onChannelDataChange(data.channelName, data.longChannelClaimId, data.shortChannelClaimId); this.setState({
name : data.channelName,
longId : data.longChannelClaimId,
shortId: data.shortChannelClaimId,
});
}) })
.catch((error) => { .catch((error) => {
that.setState({error: error.message}); that.setState({error: error.message});
@ -43,12 +50,17 @@ class ShowChannel extends React.Component {
) : ( ) : (
<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: {this.props.channel.name}</h2> <h2>channel name: {this.state.name ? this.state.name : 'loading...'}</h2>
<p>full channel id: {this.props.channel.longId ? this.props.channel.longId : 'loading...'}</p> <p>full channel id: {this.state.longId ? this.state.longId : 'loading...'}</p>
<p>short channel id: {this.props.channel.shortId ? this.props.channel.shortId : 'loading...'}</p> <p>short channel id: {this.state.shortId ? this.state.shortId : 'loading...'}</p>
</div> </div>
<div className="column column--10"> <div className="column column--10">
{this.props.channel.name && <ChannelClaimsDisplay/>} {(this.state.name && this.state.longId) &&
<ChannelClaimsDisplay
name={this.state.name}
longId={this.state.longId}
/>
}
</div> </div>
</div> </div>
)} )}

View file

@ -18,18 +18,6 @@ const initialState = {
}, },
extension: null, extension: null,
}, },
channelData: {
name : null,
shortId: null,
longId : null,
},
channelClaimsData: {
claims : null,
currentPage: 1,
totalPages : null,
totalClaims: null,
},
assetData: null,
}; };
/* /*
@ -61,27 +49,6 @@ export default function (state = initialState, action) {
extension: action.extension, extension: action.extension,
}, },
}); });
case actions.CHANNEL_DATA_UPDATE:
return Object.assign({}, state, {
channelData: Object.assign({}, state.channel, {
name : action.name,
shortId: action.shortId,
longId : action.longId,
}),
});
case actions.CHANNEL_CLAIMS_DATA_UPDATE:
return Object.assign({}, state, {
channelClaimsData: {
claims : action.claims,
currentPage: action.currentPage,
totalPages : action.totalPages,
totalClaims: action.totalClaims,
},
});
case actions.ASSET_DATA_UPDATE:
return Object.assign({}, state, {
assetData: action.data,
});
default: default:
return state; return state;
} }

View file

@ -29,13 +29,13 @@ module.exports = (app) => {
app.get('/api/file-is-available/:name/:claimId', ({ ip, originalUrl, params }, res) => { app.get('/api/file-is-available/:name/:claimId', ({ ip, originalUrl, params }, res) => {
const name = params.name; const name = params.name;
const claimId = params.claimId; const claimId = params.claimId;
let isLocalFileAvailable = false; let isAvailable = false;
db.File.findOne({where: {name, claimId}}) db.File.findOne({where: {name, claimId}})
.then(result => { .then(result => {
if (result) { if (result) {
isLocalFileAvailable = true; isAvailable = true;
} }
res.status(200).json({status: 'success', message: isLocalFileAvailable}); res.status(200).json({success: true, data: isAvailable});
}) })
.catch(error => { .catch(error => {
errorHandlers.handleApiError(originalUrl, ip, error, res); errorHandlers.handleApiError(originalUrl, ip, error, res);
@ -61,7 +61,7 @@ module.exports = (app) => {
return Promise.all([db.upsert(db.File, fileData, {name, claimId}, 'File'), getResult]); return Promise.all([db.upsert(db.File, fileData, {name, claimId}, 'File'), getResult]);
}) })
.then(([ fileRecord, {message, completed} ]) => { .then(([ fileRecord, {message, completed} ]) => {
res.status(200).json({ status: 'success', message, completed }); res.status(200).json({ success: true, message, completed });
}) })
.catch(error => { .catch(error => {
errorHandlers.handleApiError(originalUrl, ip, error, res); errorHandlers.handleApiError(originalUrl, ip, error, res);