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 19:02:29 +01:00
|
|
|
const {requestId, requestChannelName, requestChannelId, requestList, channelList} = this.props;
|
2018-02-08 08:02:57 +01:00
|
|
|
const existingRequest = requestList[requestId];
|
|
|
|
if (existingRequest) {
|
2018-02-08 19:02:29 +01:00
|
|
|
this.onRepeatChannelRequest(existingRequest, channelList);
|
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 19:02:29 +01:00
|
|
|
const {requestId, requestChannelName, requestChannelId, requestList, channelList} = nextProps;
|
2018-02-08 08:02:57 +01:00
|
|
|
const existingRequest = requestList[requestId];
|
|
|
|
if (existingRequest) {
|
2018-02-08 19:02:29 +01:00
|
|
|
this.onRepeatChannelRequest(existingRequest, channelList);
|
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-08 22:22:54 +01:00
|
|
|
} else {
|
|
|
|
console.log('ShowChannel receiving new props -> request.id did not update', nextProps);
|
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 19:59:49 +01:00
|
|
|
onRepeatChannelRequest ({ error, channelData }, channelList) {
|
2018-02-08 07:22:17 +01:00
|
|
|
// if error, return and update state with error
|
|
|
|
if (error) {
|
|
|
|
return this.props.onRequestError(error);
|
|
|
|
}
|
2018-02-08 19:02:29 +01:00
|
|
|
// check if the channel data is present or not
|
2018-02-08 19:59:49 +01:00
|
|
|
const channelRecordId = `c#${channelData.name}#${channelData.longId}`;
|
|
|
|
const existingChannel = channelList[channelRecordId];
|
2018-02-08 19:02:29 +01:00
|
|
|
if (existingChannel) {
|
2018-02-09 01:42:13 +01:00
|
|
|
this.showExistingChannel(channelRecordId);
|
2018-02-08 19:02:29 +01:00
|
|
|
} else {
|
2018-02-08 23:01:45 +01:00
|
|
|
this.showNewChannel(channelData);
|
2018-02-08 19:02:29 +01:00
|
|
|
}
|
2018-01-30 18:00:02 +01:00
|
|
|
}
|
2018-02-08 23:01:45 +01:00
|
|
|
showNewChannel (channelData) {
|
|
|
|
this.props.onShowNewChannel(channelData);
|
2018-02-08 19:02:29 +01:00
|
|
|
};
|
2018-02-09 01:42:13 +01:00
|
|
|
showExistingChannel (channelRecordId) {
|
|
|
|
this.props.onShowExistingChannel(channelRecordId);
|
2018-02-08 19:02:29 +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-09 01:42:13 +01:00
|
|
|
const { error, channel } = this.props;
|
2018-02-07 20:30:39 +01:00
|
|
|
if (error) {
|
|
|
|
return (
|
|
|
|
<ErrorPage error={error}/>
|
|
|
|
);
|
|
|
|
};
|
2018-02-09 01:42:13 +01:00
|
|
|
if (channel) {
|
|
|
|
const { channelData: { name, longId, shortId } } = channel;
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<NavBar/>
|
|
|
|
<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>
|
|
|
|
</div>
|
|
|
|
<div className="column column--10">
|
|
|
|
{(name && longId) && <ChannelClaimsDisplay />}
|
|
|
|
</div>
|
2018-01-30 18:00:02 +01:00
|
|
|
</div>
|
2018-02-07 20:30:39 +01:00
|
|
|
</div>
|
2018-02-09 01:42:13 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<ErrorPage error={'loading channel data...'}/>
|
2018-01-30 18:00:02 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ShowChannel;
|