// @flow import React from 'react'; import BusyIndicator from 'component/common/busy-indicator'; import { FormField, FormRow } from 'component/common/form'; import ReactPaginate from 'react-paginate'; import Button from 'component/button'; import SubscribeButton from 'component/subscribeButton'; import Page from 'component/page'; import FileList from 'component/fileList'; import * as modals from 'constants/modal_types'; type Props = { uri: string, page: number, totalPages: number, fetching: boolean, params: { page: number }, claim: { name: string, claim_id: string, }, claimsInChannel: Array<{}>, fetchClaims: (string, number) => void, fetchClaimCount: string => void, navigate: (string, {}) => void, openModal: (string, {}) => void, }; class ChannelPage extends React.PureComponent { componentDidMount() { const { uri, page, fetchClaims, fetchClaimCount } = this.props; fetchClaims(uri, page || 1); fetchClaimCount(uri); } componentWillReceiveProps(nextProps: Props) { const { page, uri, fetchClaims, fetchClaimCount } = this.props; if (nextProps.page && page !== nextProps.page) { fetchClaims(nextProps.uri, nextProps.page); } if (nextProps.uri !== uri) { fetchClaimCount(uri); } } changePage(pageNumber: number) { const { params } = this.props; const newParams = Object.assign({}, params, { page: pageNumber }); this.props.navigate('/show', newParams); } paginate(e, totalPages) { // Change page if enter was pressed, and the given page is between // the first and the last. if (e.keyCode === 13 && e.target.value > 0 && e.target.value <= totalPages) { this.changePage(e.target.value); } } render() { const { fetching, claimsInChannel, claim, uri, page, totalPages, openModal } = this.props; const { name } = claim; let contentList; if (fetching) { contentList = ; } else { contentList = claimsInChannel && claimsInChannel.length ? ( ) : ( {__('No content found.')} ); } return (

{name}

{contentList}
{(!fetching || (claimsInChannel && claimsInChannel.length)) && totalPages > 1 && ( this.changePage(e.selected + 1)} initialPage={parseInt(page - 1, 10)} containerClassName="pagination" /> this.paginate(e, totalPages)} prefix={__('Go to page:')} type="text" /> )}
); } } export default ChannelPage;