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

{name} {fetching && }

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