2018-02-01 01:00:11 +01:00
|
|
|
import React from 'react';
|
2018-02-02 03:42:03 +01:00
|
|
|
import AssetPreview from 'components/AssetPreview/index';
|
2018-02-01 01:00:11 +01:00
|
|
|
import request from 'utils/request';
|
|
|
|
|
|
|
|
class ChannelClaimsDisplay extends React.Component {
|
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
error: null,
|
|
|
|
page : 1,
|
|
|
|
};
|
|
|
|
this.getAndStoreChannelClaims = this.getAndStoreChannelClaims.bind(this);
|
|
|
|
}
|
|
|
|
componentDidMount () {
|
2018-02-02 03:42:03 +01:00
|
|
|
this.getAndStoreChannelClaims(this.props.name, this.props.id, this.state.page);
|
2018-02-01 01:00:11 +01:00
|
|
|
}
|
2018-02-02 03:42:03 +01:00
|
|
|
getAndStoreChannelClaims (name, id, page) {
|
|
|
|
if (!id) id = 'none';
|
|
|
|
const url = `/api/channel-claims/${name}/${id}/${page}`;
|
2018-02-01 01:00:11 +01:00
|
|
|
const that = this;
|
|
|
|
return request(url)
|
|
|
|
.then(({ success, message, data }) => {
|
|
|
|
console.log('api/channel-claims response:', data);
|
|
|
|
if (!success) {
|
|
|
|
return that.setState({error: message});
|
|
|
|
}
|
2018-02-02 03:42:03 +01:00
|
|
|
this.props.onClaimsDataChange(data.claims, data.currentPage, data.totalPages, data.totalResults);
|
2018-02-01 01:00:11 +01:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
that.setState({error: error.message});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{this.state.error ? (
|
|
|
|
<div className="row">
|
|
|
|
<div className="column column--10">
|
|
|
|
<p>{this.state.error}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<div className="row row--tall">
|
2018-02-02 03:42:03 +01:00
|
|
|
{this.props.claims &&
|
|
|
|
<div>
|
|
|
|
{this.props.claims.map((claim, index) => <AssetPreview
|
|
|
|
name={claim.name}
|
|
|
|
claimId={claim.claimId}
|
|
|
|
contentType={claim.contentType}
|
|
|
|
key={index}
|
|
|
|
/>)}
|
|
|
|
<p>current page: {this.props.currentPage}</p>
|
|
|
|
<p>total pages: {this.props.totalPages}</p>
|
|
|
|
<p>total claims: {this.props.totalClaims}</p>
|
|
|
|
</div>
|
|
|
|
}
|
2018-02-01 01:00:11 +01:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ChannelClaimsDisplay;
|