spee.ch/react/containers/ShowChannel/view.jsx

70 lines
2.3 KiB
React
Raw Normal View History

import React from 'react';
import NavBar from 'containers/NavBar';
2018-02-03 03:16:18 +01:00
import ChannelClaimsDisplay from 'containers/ChannelClaimsDisplay';
import request from 'utils/request';
class ShowChannel extends React.Component {
constructor (props) {
super(props);
this.state = {
2018-02-03 03:16:18 +01:00
error: null,
};
this.getAndStoreChannelData = this.getAndStoreChannelData.bind(this);
}
componentDidMount () {
this.getAndStoreChannelData(this.props.requestName, this.props.requestId);
}
componentWillReceiveProps (nextProps) {
if (nextProps.requestName !== this.props.requestName || nextProps.requestId !== this.props.requestId) {
this.getAndStoreChannelData(nextProps.requestName, nextProps.requestId);
}
}
getAndStoreChannelData (name, id) {
if (!id) id = 'none';
const url = `/api/channel-data/${name}/${id}`;
2018-01-31 19:40:26 +01:00
const that = this;
return request(url)
.then(({ success, message, data }) => {
console.log('api/channel-data response:', data);
if (!success) {
2018-01-31 19:40:26 +01:00
return that.setState({error: message});
}
2018-02-03 03:16:18 +01:00
that.setState({error: null}); // note: store this error at app level also
that.props.onChannelDataUpdate(data.channelName, data.longChannelClaimId, data.shortChannelClaimId);
})
.catch((error) => {
that.setState({error: error.message});
});
}
2018-02-03 03:16:18 +01:00
componentWillUnmount () {
this.props.onChannelDataClear();
}
render () {
return (
<div>
<NavBar/>
{this.state.error ? (
<div className="row row--tall row--padded">
<div className="column column--10">
<p>{this.state.error}</p>
</div>
</div>
) : (
<div className="row row--tall row--padded">
<div className="column column--10">
2018-02-03 03:16:18 +01:00
<h2>channel name: {this.props.name ? this.props.name : 'loading...'}</h2>
<p>full channel id: {this.props.longId ? this.props.longId : 'loading...'}</p>
<p>short channel id: {this.props.shortId ? this.props.shortId : 'loading...'}</p>
</div>
<div className="column column--10">
2018-02-03 03:16:18 +01:00
{(this.props.name && this.props.longId) && <ChannelClaimsDisplay />}
</div>
</div>
)}
</div>
);
}
};
export default ShowChannel;