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

89 lines
3.1 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;
}
function channelNameOrIdChanged (nextProps, props) {
return (nextProps.requestChannelName !== props.requestChannelName || nextProps.requestChannelName !== props.requestChannelName);
}
function existingRequest (requestId, requestList) {
return requestList[requestId];
}
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);
}
}
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-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;