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

64 lines
2.1 KiB
React
Raw Normal View History

import React from 'react';
import AssetPreview from 'components/AssetPreview';
class ChannelClaimsDisplay extends React.Component {
constructor (props) {
super(props);
2018-02-07 07:28:17 +01:00
this.showNextResultsPage = this.showNextResultsPage.bind(this);
this.showPreviousResultsPage = this.showPreviousResultsPage.bind(this);
}
showPreviousResultsPage () {
const { channel: { claimsData: { currentPage } } } = this.props;
const previousPage = parseInt(currentPage) - 1;
2018-02-08 22:22:54 +01:00
this.showNewPage(previousPage);
}
showNextResultsPage () {
const { channel: { claimsData: { currentPage } } } = this.props;
const nextPage = parseInt(currentPage) + 1;
2018-02-08 22:22:54 +01:00
this.showNewPage(nextPage);
}
showNewPage (page) {
const { showChannelId, channel: { channelData: { name, longId } } } = this.props;
console.log(`update claims data on channel ${showChannelId} with new page ${page}`);
this.props.onChannelPageUpdate(showChannelId, name, longId, page);
}
render () {
2018-02-09 01:42:13 +01:00
const { channel: { error, claimsData: { claims, currentPage, totalPages } } } = this.props;
return (
<div>
2018-02-08 22:22:54 +01:00
{error ? (
<div className="row">
<div className="column column--10">
2018-02-08 22:22:54 +01:00
<p>{error}</p>
</div>
</div>
) : (
<div className="row row--tall">
2018-02-08 22:22:54 +01:00
{claims &&
<div>
2018-02-08 22:22:54 +01:00
{claims.map((claim, index) => <AssetPreview
name={claim.name}
claimId={claim.claimId}
fileExt={claim.fileExt}
contentType={claim.contentType}
key={`${claim.name}-${index}`}
/>)}
<div>
2018-02-08 22:22:54 +01:00
{(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
}
2018-02-08 22:22:54 +01:00
{(currentPage < 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;