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

77 lines
2.5 KiB
React
Raw Normal View History

import React from 'react';
import ErrorPage from 'components/ErrorPage';
import NavBar from 'containers/NavBar';
2018-02-03 03:16:18 +01:00
import ChannelClaimsDisplay from 'containers/ChannelClaimsDisplay';
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
}
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
}
}
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);
}
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-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
}
render () {
const { error, name, longId, shortId } = this.props;
if (error) {
return (
<ErrorPage error={error}/>
);
};
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>
</div>
</div>
);
}
};
export default ShowChannel;