2018-03-26 23:32:43 +02:00
|
|
|
|
// @flow
|
2017-12-21 22:08:54 +01:00
|
|
|
|
import React from 'react';
|
2018-03-26 23:32:43 +02:00
|
|
|
|
import BusyIndicator from 'component/common/busy-indicator';
|
2018-03-22 17:14:26 +01:00
|
|
|
|
import { FormField, FormRow } from 'component/common/form';
|
2017-12-21 22:08:54 +01:00
|
|
|
|
import ReactPaginate from 'react-paginate';
|
|
|
|
|
import SubscribeButton from 'component/subscribeButton';
|
2018-03-30 18:13:11 +02:00
|
|
|
|
import ViewOnWebButton from 'component/viewOnWebButton';
|
2018-03-26 23:32:43 +02:00
|
|
|
|
import Page from 'component/page';
|
|
|
|
|
import FileList from 'component/fileList';
|
2018-07-11 05:29:10 +02:00
|
|
|
|
import HiddenNsfwClaims from 'component/hiddenNsfwClaims';
|
2018-05-07 06:50:55 +02:00
|
|
|
|
import type { Claim } from 'types/claim';
|
2017-05-04 05:44:08 +02:00
|
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
|
type Props = {
|
|
|
|
|
uri: string,
|
|
|
|
|
page: number,
|
|
|
|
|
totalPages: number,
|
|
|
|
|
fetching: boolean,
|
|
|
|
|
params: { page: number },
|
2018-05-07 06:50:55 +02:00
|
|
|
|
claim: Claim,
|
2018-07-11 05:29:10 +02:00
|
|
|
|
claimsInChannel: Array<Claim>,
|
2018-07-12 20:40:14 +02:00
|
|
|
|
channelIsMine: boolean,
|
2018-03-26 23:32:43 +02:00
|
|
|
|
fetchClaims: (string, number) => void,
|
|
|
|
|
fetchClaimCount: string => void,
|
|
|
|
|
navigate: (string, {}) => void,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ChannelPage extends React.PureComponent<Props> {
|
2017-05-13 00:50:51 +02:00
|
|
|
|
componentDidMount() {
|
2017-09-08 05:15:05 +02:00
|
|
|
|
const { uri, page, fetchClaims, fetchClaimCount } = this.props;
|
2017-07-17 08:06:04 +02:00
|
|
|
|
|
2017-09-08 05:15:05 +02:00
|
|
|
|
fetchClaims(uri, page || 1);
|
2017-08-24 23:12:23 +02:00
|
|
|
|
fetchClaimCount(uri);
|
2017-05-13 00:50:51 +02:00
|
|
|
|
}
|
2017-05-04 05:44:08 +02:00
|
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
|
componentWillReceiveProps(nextProps: Props) {
|
2018-03-22 17:14:26 +01:00
|
|
|
|
const { page, uri, fetchClaims, fetchClaimCount } = this.props;
|
2017-07-17 08:06:04 +02:00
|
|
|
|
|
2017-09-20 19:12:53 +02:00
|
|
|
|
if (nextProps.page && page !== nextProps.page) {
|
2017-09-08 05:15:05 +02:00
|
|
|
|
fetchClaims(nextProps.uri, nextProps.page);
|
2017-08-24 23:12:23 +02:00
|
|
|
|
}
|
2018-03-22 17:14:26 +01:00
|
|
|
|
if (nextProps.uri !== uri) {
|
2017-08-24 23:12:23 +02:00
|
|
|
|
fetchClaimCount(uri);
|
|
|
|
|
}
|
2017-05-13 00:50:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
|
changePage(pageNumber: number) {
|
2017-09-20 16:57:43 +02:00
|
|
|
|
const { params } = this.props;
|
2017-07-17 08:06:04 +02:00
|
|
|
|
const newParams = Object.assign({}, params, { page: pageNumber });
|
|
|
|
|
|
2017-12-21 22:08:54 +01:00
|
|
|
|
this.props.navigate('/show', newParams);
|
2017-05-13 00:50:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-10 16:25:38 +02:00
|
|
|
|
paginate(e: SyntheticKeyboardEvent<*>, totalPages: number) {
|
2018-03-22 17:14:26 +01:00
|
|
|
|
// Change page if enter was pressed, and the given page is between
|
|
|
|
|
// the first and the last.
|
2018-07-11 05:29:10 +02:00
|
|
|
|
const pageFromInput = Number(e.currentTarget.value);
|
2018-05-31 05:50:12 +02:00
|
|
|
|
|
|
|
|
|
if (
|
2018-07-11 05:29:10 +02:00
|
|
|
|
pageFromInput &&
|
2018-05-31 05:50:12 +02:00
|
|
|
|
e.keyCode === 13 &&
|
|
|
|
|
!Number.isNaN(pageFromInput) &&
|
|
|
|
|
pageFromInput > 0 &&
|
|
|
|
|
pageFromInput <= totalPages
|
|
|
|
|
) {
|
|
|
|
|
this.changePage(pageFromInput);
|
2018-03-22 17:14:26 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-13 00:50:51 +02:00
|
|
|
|
render() {
|
2018-07-12 20:40:14 +02:00
|
|
|
|
const { uri, fetching, claimsInChannel, claim, page, totalPages, channelIsMine } = this.props;
|
2018-03-30 18:13:11 +02:00
|
|
|
|
const { name, permanent_url: permanentUrl, claim_id: claimId } = claim;
|
2018-06-21 08:01:19 +02:00
|
|
|
|
const currentPage = parseInt((page || 1) - 1, 10);
|
2018-07-10 16:25:38 +02:00
|
|
|
|
|
|
|
|
|
const contentList =
|
|
|
|
|
claimsInChannel && claimsInChannel.length ? (
|
|
|
|
|
<FileList sortByHeight hideFilter fileInfos={claimsInChannel} />
|
|
|
|
|
) : (
|
|
|
|
|
!fetching && <span className="empty">{__('No content found.')}</span>
|
|
|
|
|
);
|
2017-05-21 16:42:34 +02:00
|
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
|
return (
|
2018-03-26 23:32:43 +02:00
|
|
|
|
<Page notContained>
|
2018-10-09 17:01:54 +02:00
|
|
|
|
<section>
|
2018-07-10 16:25:38 +02:00
|
|
|
|
<h1>
|
|
|
|
|
{name}
|
|
|
|
|
{fetching && <BusyIndicator />}
|
|
|
|
|
</h1>
|
2017-06-06 23:19:12 +02:00
|
|
|
|
</section>
|
2018-10-04 06:39:49 +02:00
|
|
|
|
<div className="card__actions">
|
2018-10-31 18:08:30 +01:00
|
|
|
|
<SubscribeButton uri={`lbry://${permanentUrl}`} channelName={name} />
|
2018-10-04 06:39:49 +02:00
|
|
|
|
<ViewOnWebButton claimId={claimId} claimName={name} />
|
|
|
|
|
</div>
|
|
|
|
|
<section className="card__content">{contentList}</section>
|
2017-07-17 08:06:04 +02:00
|
|
|
|
{(!fetching || (claimsInChannel && claimsInChannel.length)) &&
|
2017-11-24 15:31:05 +01:00
|
|
|
|
totalPages > 1 && (
|
2018-03-22 17:14:26 +01:00
|
|
|
|
<FormRow verticallyCentered centered>
|
|
|
|
|
<ReactPaginate
|
|
|
|
|
pageCount={totalPages}
|
|
|
|
|
pageRangeDisplayed={2}
|
|
|
|
|
previousLabel="‹"
|
|
|
|
|
nextLabel="›"
|
|
|
|
|
activeClassName="pagination__item--selected"
|
|
|
|
|
pageClassName="pagination__item"
|
|
|
|
|
previousClassName="pagination__item pagination__item--previous"
|
|
|
|
|
nextClassName="pagination__item pagination__item--next"
|
|
|
|
|
breakClassName="pagination__item pagination__item--break"
|
|
|
|
|
marginPagesDisplayed={2}
|
|
|
|
|
onPageChange={e => this.changePage(e.selected + 1)}
|
2018-06-21 08:01:19 +02:00
|
|
|
|
forcePage={currentPage}
|
|
|
|
|
initialPage={currentPage}
|
2018-03-22 17:14:26 +01:00
|
|
|
|
containerClassName="pagination"
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<FormField
|
|
|
|
|
className="paginate-channel"
|
|
|
|
|
onKeyUp={e => this.paginate(e, totalPages)}
|
|
|
|
|
prefix={__('Go to page:')}
|
|
|
|
|
type="text"
|
|
|
|
|
/>
|
|
|
|
|
</FormRow>
|
2017-11-24 15:31:05 +01:00
|
|
|
|
)}
|
2018-07-12 20:40:14 +02:00
|
|
|
|
{!channelIsMine && <HiddenNsfwClaims className="card__content help" uri={uri} />}
|
2018-03-26 23:32:43 +02:00
|
|
|
|
</Page>
|
2017-06-06 23:19:12 +02:00
|
|
|
|
);
|
2017-05-13 00:50:51 +02:00
|
|
|
|
}
|
2017-05-04 05:44:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default ChannelPage;
|