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;
|
|
|
|
}
|
|
|
|
|
|
|
|
function channelNameOrIdChanged (nextProps, props) {
|
|
|
|
return (nextProps.requestChannelName !== props.requestChannelName || nextProps.requestChannelName !== props.requestChannelName);
|
|
|
|
}
|
|
|
|
|
|
|
|
function existingRequest (requestId, requestList) {
|
|
|
|
return requestList[requestId];
|
|
|
|
}
|
|
|
|
|
2018-01-30 18:00:02 +01:00
|
|
|
class ShowChannel extends React.Component {
|
|
|
|
componentDidMount () {
|
2018-02-08 05:15:44 +01:00
|
|
|
console.log('showchannel did mount');
|
2018-02-08 06:30:32 +01:00
|
|
|
const {requestId, requestName, requestChannelId, requestList} = this.props;
|
|
|
|
if (existingRequest(requestId, requestList)) {
|
|
|
|
// const validRequest = existingRequest(requestId, requestList);
|
|
|
|
// this.onRepeatChannelRequest(validRequest);
|
2018-02-08 07:22:17 +01:00
|
|
|
console.log('we got a repeat channel request on an unmounted ShowChannel component');
|
2018-02-08 06:30:32 +01:00
|
|
|
} else {
|
|
|
|
this.onNewChannelRequest(requestId, requestName, requestChannelId);
|
|
|
|
}
|
2018-02-01 01:00:11 +01:00
|
|
|
}
|
2018-02-03 01:49:39 +01:00
|
|
|
componentWillReceiveProps (nextProps) {
|
2018-02-08 06:30:32 +01:00
|
|
|
console.log('showchannel will receive new props');
|
|
|
|
if (requestIsAChannelRequest(nextProps) && channelNameOrIdChanged(nextProps, this.props)) {
|
|
|
|
const {requestId, requestList} = nextProps;
|
|
|
|
if (existingRequest(requestId, requestList)) {
|
|
|
|
const request = requestList[requestId];
|
|
|
|
this.onRepeatChannelRequest(request);
|
|
|
|
} else {
|
2018-02-08 07:22:17 +01:00
|
|
|
console.log('we got a new channel request on a mounted ShowChannel component');
|
2018-02-08 06:30:32 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
onNewChannelRequest (requestId, requestName, requestChannelId) {
|
|
|
|
// validate the request (i.e. get channel full claim id)
|
|
|
|
// update teh request list
|
|
|
|
// if error, return early (set the request error in the store)
|
|
|
|
// if the request is valid...
|
|
|
|
// add it to the requestList
|
|
|
|
// update showChannel to reflect the channel details
|
|
|
|
this.props.onNewChannelRequest(requestId, requestName, requestChannelId);
|
|
|
|
}
|
|
|
|
onRepeatChannelRequest ({ id, error, name, claimId }) {
|
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;
|