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 = { error : null, claims : null, currentPage: null, totalPages : null, totalClaims: null, }; this.updateClaimsData = this.updateClaimsData.bind(this); this.showPreviousResultsPage = this.showPreviousResultsPage.bind(this); this.showNextResultsPage = this.showNextResultsPage.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) { 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}); }); } showPreviousResultsPage () { const previousPage = parseInt(this.state.currentPage) - 1; this.updateClaimsData(previousPage); } showNextResultsPage () { const nextPage = parseInt(this.state.currentPage) + 1; this.updateClaimsData(nextPage); } render () { return (
{this.state.error}