2018-01-30 18:00:02 +01:00
|
|
|
import React from 'react';
|
2018-02-07 20:30:39 +01:00
|
|
|
import ErrorPage from 'components/ErrorPage';
|
2018-01-30 18:00:02 +01:00
|
|
|
import NavBar from 'containers/NavBar';
|
2018-02-03 03:16:18 +01:00
|
|
|
import ChannelClaimsDisplay from 'containers/ChannelClaimsDisplay';
|
2018-01-30 18:00:02 +01:00
|
|
|
|
2018-02-08 06:30:32 +01:00
|
|
|
import { CHANNEL } from 'constants/show_request_types';
|
|
|
|
|
|
|
|
function requestIsAChannelRequest ({ requestType }) {
|
|
|
|
return requestType === CHANNEL;
|
|
|
|
}
|
|
|
|
|
2018-02-08 08:18:18 +01:00
|
|
|
function requestIsNewRequest (nextProps, props) {
|
|
|
|
return (nextProps.requestId !== props.requestId);
|
2018-02-08 06:30:32 +01:00
|
|
|
}
|
|
|
|
|
2018-01-30 18:00:02 +01:00
|
|
|
class ShowChannel extends React.Component {
|
|
|
|
componentDidMount () {
|
2018-02-08 08:02:57 +01:00
|
|
|
const {requestId, requestChannelName, requestChannelId, requestList} = this.props;
|
|
|
|
const existingRequest = requestList[requestId];
|
|
|
|
if (existingRequest) {
|
|
|
|
this.onRepeatChannelRequest(existingRequest);
|
2018-02-08 06:30:32 +01:00
|
|
|
} else {
|
2018-02-08 08:02:57 +01:00
|
|
|
this.onNewChannelRequest(requestId, requestChannelName, requestChannelId);
|
2018-02-08 06:30:32 +01:00
|
|
|
}
|
2018-02-01 01:00:11 +01:00
|
|
|
}
|
2018-02-03 01:49:39 +01:00
|
|
|
componentWillReceiveProps (nextProps) {
|
2018-02-08 08:18:18 +01:00
|
|
|
if (requestIsAChannelRequest(nextProps) && requestIsNewRequest(nextProps, this.props)) {
|
2018-02-08 08:02:57 +01:00
|
|
|
const {requestId, requestChannelName, requestChannelId, requestList} = nextProps;
|
|
|
|
const existingRequest = requestList[requestId];
|
|
|
|
if (existingRequest) {
|
|
|
|
this.onRepeatChannelRequest(existingRequest);
|
2018-02-08 06:30:32 +01:00
|
|
|
} else {
|
2018-02-08 08:02:57 +01:00
|
|
|
this.onNewChannelRequest(requestId, requestChannelName, requestChannelId);
|
2018-02-08 06:30:32 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
onNewChannelRequest (requestId, requestName, requestChannelId) {
|
2018-02-08 08:18:18 +01:00
|
|
|
console.log('new request');
|
2018-02-08 06:30:32 +01:00
|
|
|
this.props.onNewChannelRequest(requestId, requestName, requestChannelId);
|
|
|
|
}
|
2018-02-08 08:49:01 +01:00
|
|
|
onRepeatChannelRequest ({ id, error, data: { channelName, longChannelClaimId} }) {
|
2018-02-08 07:22:17 +01:00
|
|
|
// if error, return and update state with error
|
|
|
|
if (error) {
|
|
|
|
return this.props.onRequestError(error);
|
|
|
|
}
|
|
|
|
// if no error, get the channel's claims data
|
2018-01-30 18:00:02 +01:00
|
|
|
}
|
2018-02-03 03:16:18 +01:00
|
|
|
componentWillUnmount () {
|
2018-02-08 07:22:17 +01:00
|
|
|
this.props.onShowChannelClear();
|
2018-02-03 03:16:18 +01:00
|
|
|
}
|
2018-01-30 18:00:02 +01:00
|
|
|
render () {
|
2018-02-07 20:30:39 +01:00
|
|
|
const { error, name, longId, shortId } = this.props;
|
|
|
|
if (error) {
|
|
|
|
return (
|
|
|
|
<ErrorPage error={error}/>
|
|
|
|
);
|
|
|
|
};
|
2018-01-30 18:00:02 +01:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<NavBar/>
|
2018-02-07 20:30:39 +01:00
|
|
|
<div className="row row--tall row--padded">
|
|
|
|
<div className="column column--10">
|
|
|
|
<h2>channel name: {name ? name : 'loading...'}</h2>
|
|
|
|
<p className={'fine-print'}>full channel id: {longId ? longId : 'loading...'}</p>
|
|
|
|
<p className={'fine-print'}>short channel id: {shortId ? shortId : 'loading...'}</p>
|
2018-01-30 18:00:02 +01:00
|
|
|
</div>
|
2018-02-07 20:30:39 +01:00
|
|
|
<div className="column column--10">
|
|
|
|
{(name && longId) && <ChannelClaimsDisplay />}
|
2018-01-30 18:00:02 +01:00
|
|
|
</div>
|
2018-02-07 20:30:39 +01:00
|
|
|
</div>
|
2018-01-30 18:00:02 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ShowChannel;
|