2018-03-26 23:32:43 +02:00
|
|
|
|
// @flow
|
2018-12-19 06:44:53 +01:00
|
|
|
|
import * as icons from 'constants/icons';
|
2018-11-26 02:21:25 +01:00
|
|
|
|
import * as MODALS from 'constants/modal_types';
|
2019-03-28 17:53:13 +01:00
|
|
|
|
import React, { useEffect } from 'react';
|
2018-03-26 23:32:43 +02:00
|
|
|
|
import BusyIndicator from 'component/common/busy-indicator';
|
2019-02-20 06:20:29 +01:00
|
|
|
|
import { FormField, Form } from 'component/common/form';
|
2017-12-21 22:08:54 +01:00
|
|
|
|
import ReactPaginate from 'react-paginate';
|
|
|
|
|
import SubscribeButton from 'component/subscribeButton';
|
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-11-02 01:41:41 +01:00
|
|
|
|
import Button from 'component/button';
|
2019-04-04 23:05:23 +02:00
|
|
|
|
import { withRouter } from 'react-router-dom';
|
2017-05-04 05:44:08 +02:00
|
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
|
type Props = {
|
|
|
|
|
uri: string,
|
|
|
|
|
totalPages: number,
|
|
|
|
|
fetching: boolean,
|
|
|
|
|
params: { page: number },
|
2019-04-24 16:02:08 +02:00
|
|
|
|
claim: ChannelClaim,
|
|
|
|
|
claimsInChannel: Array<StreamClaim>,
|
2018-07-12 20:40:14 +02:00
|
|
|
|
channelIsMine: boolean,
|
2018-03-26 23:32:43 +02:00
|
|
|
|
fetchClaims: (string, number) => void,
|
2019-04-04 23:05:23 +02:00
|
|
|
|
history: { push: string => void },
|
2019-01-08 00:29:40 +01:00
|
|
|
|
openModal: (id: string, { uri: string }) => void,
|
2019-03-28 17:53:13 +01:00
|
|
|
|
location: UrlLocation,
|
2018-03-26 23:32:43 +02:00
|
|
|
|
};
|
|
|
|
|
|
2019-03-28 17:53:13 +01:00
|
|
|
|
function ChannelPage(props: Props) {
|
|
|
|
|
const {
|
|
|
|
|
uri,
|
|
|
|
|
fetching,
|
|
|
|
|
claimsInChannel,
|
|
|
|
|
claim,
|
|
|
|
|
totalPages,
|
|
|
|
|
channelIsMine,
|
|
|
|
|
openModal,
|
|
|
|
|
fetchClaims,
|
|
|
|
|
location,
|
2019-04-04 23:05:23 +02:00
|
|
|
|
history,
|
2019-03-28 17:53:13 +01:00
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
|
|
const { name, permanent_url: permanentUrl } = claim;
|
|
|
|
|
const { search } = location;
|
|
|
|
|
const urlParams = new URLSearchParams(search);
|
|
|
|
|
const page = Number(urlParams.get('page')) || 1;
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
// Fetch new claims if the channel or page number changes
|
|
|
|
|
fetchClaims(uri, page);
|
|
|
|
|
}, [uri, page]);
|
|
|
|
|
|
|
|
|
|
const changePage = (pageNumber: number) => {
|
|
|
|
|
if (!page && pageNumber === 1) {
|
|
|
|
|
return;
|
2017-08-24 23:12:23 +02:00
|
|
|
|
}
|
2017-05-13 00:50:51 +02:00
|
|
|
|
|
2019-04-04 23:05:23 +02:00
|
|
|
|
history.push(`?page=${pageNumber}`);
|
2019-03-28 17:53:13 +01:00
|
|
|
|
};
|
2017-07-17 08:06:04 +02:00
|
|
|
|
|
2019-03-28 17:53:13 +01:00
|
|
|
|
const paginate = (e: SyntheticKeyboardEvent<*>) => {
|
|
|
|
|
// Change page if enter was pressed, and the given page is between the first and the last page
|
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
|
|
|
|
|
) {
|
2019-03-28 17:53:13 +01:00
|
|
|
|
changePage(pageFromInput);
|
2018-03-22 17:14:26 +01:00
|
|
|
|
}
|
2019-03-28 17:53:13 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Page notContained>
|
|
|
|
|
<header className="channel-info">
|
|
|
|
|
<h1 className="media__title media__title--large">
|
|
|
|
|
{name}
|
|
|
|
|
{fetching && <BusyIndicator />}
|
|
|
|
|
</h1>
|
2019-04-24 16:02:08 +02:00
|
|
|
|
<span>{permanentUrl}</span>
|
2019-03-28 17:53:13 +01:00
|
|
|
|
|
|
|
|
|
<div className="channel-info__actions__group">
|
2019-04-24 16:02:08 +02:00
|
|
|
|
<SubscribeButton uri={permanentUrl} channelName={name} />
|
2019-03-28 17:53:13 +01:00
|
|
|
|
<Button
|
|
|
|
|
button="alt"
|
|
|
|
|
icon={icons.SHARE}
|
|
|
|
|
label={__('Share Channel')}
|
|
|
|
|
onClick={() =>
|
|
|
|
|
openModal(MODALS.SOCIAL_SHARE, { uri, speechShareable: true, isChannel: true })
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
<section className="media-group--list">
|
|
|
|
|
{claimsInChannel && claimsInChannel.length ? (
|
|
|
|
|
<FileList sortByHeight hideFilter fileInfos={claimsInChannel} />
|
|
|
|
|
) : (
|
|
|
|
|
!fetching && <span className="empty">{__('No content found.')}</span>
|
2019-03-05 05:46:57 +01:00
|
|
|
|
)}
|
2019-03-28 17:53:13 +01:00
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
{(!fetching || (claimsInChannel && claimsInChannel.length)) && totalPages > 1 && (
|
|
|
|
|
<Form>
|
|
|
|
|
<fieldset-group class="fieldset-group--smushed fieldgroup--paginate">
|
|
|
|
|
<fieldset-section>
|
|
|
|
|
<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 => changePage(e.selected + 1)}
|
|
|
|
|
forcePage={page - 1}
|
|
|
|
|
initialPage={page - 1}
|
|
|
|
|
disableInitialCallback
|
|
|
|
|
containerClassName="pagination"
|
|
|
|
|
/>
|
|
|
|
|
</fieldset-section>
|
|
|
|
|
|
|
|
|
|
<FormField
|
|
|
|
|
className="paginate-channel"
|
|
|
|
|
onKeyUp={e => paginate(e)}
|
|
|
|
|
label={__('Go to page:')}
|
|
|
|
|
type="text"
|
|
|
|
|
name="paginate-file"
|
|
|
|
|
/>
|
|
|
|
|
</fieldset-group>
|
|
|
|
|
</Form>
|
|
|
|
|
)}
|
2018-12-19 06:44:53 +01:00
|
|
|
|
|
2019-03-28 17:53:13 +01:00
|
|
|
|
{!channelIsMine && <HiddenNsfwClaims className="card__content help" uri={uri} />}
|
|
|
|
|
</Page>
|
|
|
|
|
);
|
2017-05-04 05:44:08 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-04 23:05:23 +02:00
|
|
|
|
export default withRouter(ChannelPage);
|