2018-01-30 18:00:02 +01:00
|
|
|
import React from 'react';
|
|
|
|
import NavBar from 'containers/NavBar';
|
2018-02-01 01:00:11 +01:00
|
|
|
import ChannelClaimsDisplay from 'components/ChannelClaimsDisplay';
|
2018-01-30 20:46:22 +01:00
|
|
|
import request from 'utils/request';
|
2018-01-30 18:00:02 +01:00
|
|
|
|
|
|
|
class ShowChannel extends React.Component {
|
2018-01-30 20:46:22 +01:00
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2018-02-01 01:00:11 +01:00
|
|
|
error: null,
|
2018-01-30 20:46:22 +01:00
|
|
|
};
|
2018-02-01 01:00:11 +01:00
|
|
|
this.getAndStoreChannelData = this.getAndStoreChannelData.bind(this);
|
2018-01-30 20:46:22 +01:00
|
|
|
}
|
2018-01-30 18:00:02 +01:00
|
|
|
componentDidMount () {
|
2018-01-30 20:46:22 +01:00
|
|
|
const channelName = this.props.channelName;
|
|
|
|
const channelClaimId = this.props.channelClaimId || 'none';
|
2018-02-01 01:00:11 +01:00
|
|
|
this.getAndStoreChannelData(channelName, channelClaimId);
|
|
|
|
}
|
|
|
|
getAndStoreChannelData (channelName, channelClaimId) {
|
|
|
|
const url = `/api/channel-data/${channelName}/${channelClaimId}`;
|
2018-01-31 19:40:26 +01:00
|
|
|
const that = this;
|
2018-01-30 20:46:22 +01:00
|
|
|
return request(url)
|
|
|
|
.then(({ success, message, data }) => {
|
2018-02-01 01:00:11 +01:00
|
|
|
console.log('api/channel-data response:', data);
|
2018-01-30 20:46:22 +01:00
|
|
|
if (!success) {
|
2018-01-31 19:40:26 +01:00
|
|
|
return that.setState({error: message});
|
2018-01-30 20:46:22 +01:00
|
|
|
}
|
|
|
|
that.setState({
|
|
|
|
channelName : data.channelName,
|
|
|
|
longChannelClaimId : data.longChannelClaimId,
|
|
|
|
shortChannelClaimId: data.shortChannelClaimId,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
that.setState({error: error.message});
|
|
|
|
});
|
2018-01-30 18:00:02 +01:00
|
|
|
}
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<NavBar/>
|
2018-01-30 20:46:22 +01:00
|
|
|
{this.state.error ? (
|
|
|
|
<div className="row row--tall row--padded">
|
|
|
|
<div className="column column--10">
|
|
|
|
<p>{this.state.error}</p>
|
|
|
|
</div>
|
2018-01-30 18:00:02 +01:00
|
|
|
</div>
|
2018-01-30 20:46:22 +01:00
|
|
|
) : (
|
|
|
|
<div className="row row--tall row--padded">
|
|
|
|
<div className="column column--10">
|
|
|
|
<h2>channel name: {this.props.channelName}</h2>
|
|
|
|
<p>full channel id: {this.state.longChannelClaimId ? this.state.longChannelClaimId : 'loading...'}</p>
|
|
|
|
<p>short channel id: {this.state.shortChannelClaimId ? this.state.shortChannelClaimId : 'loading...'}</p>
|
|
|
|
</div>
|
|
|
|
<div className="column column--10">
|
2018-02-01 01:00:11 +01:00
|
|
|
{ (this.state.channelName && this.state.longChannelClaimId) &&
|
|
|
|
<ChannelClaimsDisplay
|
|
|
|
channelName={this.state.channelName}
|
|
|
|
channelClaimId={this.state.longChannelClaimId}
|
|
|
|
/>
|
|
|
|
}
|
2018-01-30 18:00:02 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
2018-01-30 20:46:22 +01:00
|
|
|
)}
|
2018-01-30 18:00:02 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// required props
|
|
|
|
// channelName
|
2018-01-30 20:46:22 +01:00
|
|
|
// channelClaimId
|
|
|
|
|
2018-01-30 18:00:02 +01:00
|
|
|
|
|
|
|
export default ShowChannel;
|