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

76 lines
2.4 KiB
React
Raw Normal View History

import React from 'react';
import AssetPreview from 'components/AssetPreview';
import request from 'utils/request';
class ChannelClaimsDisplay extends React.Component {
constructor (props) {
super(props);
this.state = {
2018-02-03 03:16:18 +01:00
error: null,
};
2018-02-07 07:28:17 +01:00
this.showNextResultsPage = this.showNextResultsPage.bind(this);
this.showPreviousResultsPage = this.showPreviousResultsPage.bind(this);
}
componentDidMount () {
const name = this.props.name;
const longId = this.props.longId;
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) {
console.log('this function has been moved into the redux sagas');
}
2018-02-03 03:16:18 +01:00
componentWillUnmount () {
this.props.onChannelClaimsDataClear();
}
showPreviousResultsPage () {
2018-02-03 03:16:18 +01:00
const previousPage = parseInt(this.props.currentPage) - 1;
this.updateClaimsData(this.props.name, this.props.longId, previousPage);
}
showNextResultsPage () {
2018-02-03 03:16:18 +01:00
const nextPage = parseInt(this.props.currentPage) + 1;
this.updateClaimsData(this.props.name, this.props.longId, nextPage);
}
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-03 03:16:18 +01:00
{this.props.claims &&
<div>
2018-02-03 03:16:18 +01:00
{this.props.claims.map((claim, index) => <AssetPreview
name={claim.name}
claimId={claim.claimId}
fileExt={claim.fileExt}
contentType={claim.contentType}
key={`${claim.name}-${index}`}
/>)}
<div>
2018-02-07 07:28:17 +01:00
{(this.props.currentPage > 1) &&
2018-02-07 07:54:06 +01:00
<button className={'button--secondary'} onClick={this.showPreviousResultsPage}>Previous Page</button>
2018-02-07 07:28:17 +01:00
}
{(this.props.currentPage < this.props.totalPages) &&
2018-02-07 07:54:06 +01:00
<button className={'button--secondary'} onClick={this.showNextResultsPage}>Next Page</button>
2018-02-07 07:28:17 +01:00
}
</div>
</div>
}
</div>
)}
</div>
);
}
};
export default ChannelClaimsDisplay;