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

64 lines
2.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';
import request from 'utils/request';
class ShowChannel extends React.Component {
componentDidMount () {
2018-02-08 05:15:44 +01:00
console.log('showchannel did mount');
const {requestChannelName, requestChannelId} = this.props;
this.getAndStoreChannelData(requestChannelName, requestChannelId);
}
componentWillReceiveProps (nextProps) {
2018-02-08 05:15:44 +01:00
if (nextProps.channelRequests !== this.props.channelRequests) {
const {requestChannelName, requestChannelId} = nextProps;
this.getAndStoreChannelData(requestChannelName, requestChannelId);
}
}
getAndStoreChannelData (name, id) {
2018-02-08 05:15:44 +01:00
console.log('getting and storing channel data for channel:', name, id);
if (!id) id = 'none';
2018-02-07 06:55:04 +01:00
const url = `/api/channel/data/${name}/${id}`;
return request(url)
.then(({ success, message, data }) => {
console.log('api/channel/data/ response:', data);
if (!success) {
return this.props.onShowChannelError(message);
}
2018-02-07 00:05:31 +01:00
this.props.onChannelDataUpdate(data.channelName, data.longChannelClaimId, data.shortChannelClaimId);
})
.catch((error) => {
return this.props.onShowChannelError(error.message);
});
}
2018-02-03 03:16:18 +01:00
componentWillUnmount () {
this.props.onChannelDataClear();
}
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;