2018-02-02 23:24:46 +01:00
|
|
|
import React from 'react';
|
2018-02-02 21:46:18 +01:00
|
|
|
import AssetPreview from 'components/AssetPreview';
|
|
|
|
import request from 'utils/request';
|
|
|
|
|
|
|
|
class ChannelClaimsDisplay extends React.Component {
|
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
error : null,
|
|
|
|
claims : null,
|
|
|
|
currentPage: null,
|
|
|
|
totalPages : null,
|
|
|
|
totalClaims: null,
|
|
|
|
};
|
|
|
|
this.updateClaimsData = this.updateClaimsData.bind(this);
|
2018-02-03 01:06:21 +01:00
|
|
|
this.showPreviousResultsPage = this.showPreviousResultsPage.bind(this);
|
|
|
|
this.showNextResultsPage = this.showNextResultsPage.bind(this);
|
2018-02-02 21:46:18 +01:00
|
|
|
}
|
|
|
|
componentDidMount () {
|
|
|
|
const name = this.props.name;
|
|
|
|
const longId = this.props.longId;
|
2018-02-03 01:49:39 +01:00
|
|
|
this.updateClaimsData(name, longId, 1);
|
|
|
|
}
|
|
|
|
componentWillReceiveProps (nextProps) {
|
|
|
|
if (nextProps.name !== this.props.name || nextProps.longId !== this.props.longId) {
|
|
|
|
this.updateClaimsData(nextProps.name, nextProps.longId, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateClaimsData (name, longId, page) {
|
2018-02-02 21:46:18 +01:00
|
|
|
const url = `/api/channel-claims/${name}/${longId}/${page}`;
|
|
|
|
const that = this;
|
|
|
|
return request(url)
|
|
|
|
.then(({ success, message, data }) => {
|
|
|
|
console.log('api/channel-claims response:', data);
|
|
|
|
if (!success) {
|
|
|
|
return that.setState({error: message});
|
|
|
|
}
|
|
|
|
this.setState({
|
|
|
|
claims : data.claims,
|
|
|
|
currentPage: data.currentPage,
|
|
|
|
totalPages : data.totalPages,
|
|
|
|
totalClaims: data.totalResults,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
that.setState({error: error.message});
|
|
|
|
});
|
|
|
|
}
|
2018-02-03 01:06:21 +01:00
|
|
|
showPreviousResultsPage () {
|
|
|
|
const previousPage = parseInt(this.state.currentPage) - 1;
|
|
|
|
this.updateClaimsData(previousPage);
|
|
|
|
}
|
|
|
|
showNextResultsPage () {
|
|
|
|
const nextPage = parseInt(this.state.currentPage) + 1;
|
|
|
|
this.updateClaimsData(nextPage);
|
|
|
|
}
|
2018-02-02 21:46:18 +01:00
|
|
|
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">
|
|
|
|
{this.state.claims &&
|
|
|
|
<div>
|
|
|
|
{this.state.claims.map((claim, index) => <AssetPreview
|
|
|
|
name={claim.name}
|
|
|
|
claimId={claim.claimId}
|
2018-02-02 22:06:28 +01:00
|
|
|
fileExt={claim.fileExt}
|
2018-02-02 21:46:18 +01:00
|
|
|
contentType={claim.contentType}
|
2018-02-03 01:06:21 +01:00
|
|
|
key={`${claim.name}-${index}`}
|
2018-02-02 21:46:18 +01:00
|
|
|
/>)}
|
2018-02-03 01:06:21 +01:00
|
|
|
<div>
|
|
|
|
{(this.state.currentPage > 1) && <button onClick={this.showPreviousResultsPage}>Previous Page</button>}
|
|
|
|
{(this.state.currentPage < this.state.totalPages) && <button onClick={this.showNextResultsPage}>Next Page</button>}
|
|
|
|
</div>
|
2018-02-02 21:46:18 +01:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// PropTypes
|
|
|
|
// name
|
|
|
|
// id
|
|
|
|
|
|
|
|
export default ChannelClaimsDisplay;
|