2017-06-06 23:19:12 +02:00
|
|
|
|
import React from "react";
|
|
|
|
|
import lbryuri from "lbryuri";
|
|
|
|
|
import { BusyMessage } from "component/common";
|
|
|
|
|
import FileTile from "component/fileTile";
|
2017-07-17 08:06:04 +02:00
|
|
|
|
import ReactPaginate from "react-paginate";
|
2017-12-08 21:14:35 +01:00
|
|
|
|
import Link from "component/link";
|
2017-05-04 05:44:08 +02:00
|
|
|
|
|
2017-06-08 06:42:19 +02:00
|
|
|
|
class ChannelPage extends React.PureComponent {
|
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
|
|
|
|
|
2017-05-13 00:50:51 +02:00
|
|
|
|
componentWillReceiveProps(nextProps) {
|
2017-09-08 05:15:05 +02:00
|
|
|
|
const { page, uri, fetching, 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
|
|
|
|
}
|
2017-09-08 05:15:05 +02:00
|
|
|
|
if (nextProps.uri != uri) {
|
2017-08-24 23:12:23 +02:00
|
|
|
|
fetchClaimCount(uri);
|
|
|
|
|
}
|
2017-05-13 00:50:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-17 08:06:04 +02:00
|
|
|
|
changePage(pageNumber) {
|
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 });
|
|
|
|
|
|
|
|
|
|
this.props.navigate("/show", newParams);
|
2017-05-13 00:50:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
2017-07-17 08:06:04 +02:00
|
|
|
|
const {
|
|
|
|
|
fetching,
|
|
|
|
|
claimsInChannel,
|
|
|
|
|
claim,
|
|
|
|
|
uri,
|
2017-09-08 05:15:05 +02:00
|
|
|
|
page,
|
2017-07-17 08:06:04 +02:00
|
|
|
|
totalPages,
|
2017-12-08 21:14:35 +01:00
|
|
|
|
channelSubscribe,
|
|
|
|
|
channelUnsubscribe,
|
|
|
|
|
subscriptions,
|
2017-07-17 08:06:04 +02:00
|
|
|
|
} = this.props;
|
2017-05-13 00:50:51 +02:00
|
|
|
|
|
2017-12-08 21:14:35 +01:00
|
|
|
|
const { name, claim_id: claimId } = claim;
|
|
|
|
|
|
|
|
|
|
const isSubscribed =
|
|
|
|
|
subscriptions
|
|
|
|
|
.map(subscription => subscription.channelName)
|
|
|
|
|
.indexOf(name) !== -1;
|
|
|
|
|
|
|
|
|
|
const subscriptionHandler = isSubscribed
|
|
|
|
|
? channelUnsubscribe
|
|
|
|
|
: channelSubscribe;
|
|
|
|
|
|
|
|
|
|
const subscriptionLabel = isSubscribed ? "Unsubscribe" : "Subscribe";
|
|
|
|
|
const subscriptionUri = lbryuri.build(
|
|
|
|
|
{ channelName: name, claimId },
|
|
|
|
|
false
|
|
|
|
|
);
|
|
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
|
let contentList;
|
2017-09-20 19:12:53 +02:00
|
|
|
|
if (fetching) {
|
2017-06-06 23:19:12 +02:00
|
|
|
|
contentList = <BusyMessage message={__("Fetching content")} />;
|
2017-09-20 19:12:53 +02:00
|
|
|
|
} else {
|
2017-11-24 15:31:05 +01:00
|
|
|
|
contentList =
|
|
|
|
|
claimsInChannel && claimsInChannel.length ? (
|
|
|
|
|
claimsInChannel.map(claim => (
|
2017-06-06 23:19:12 +02:00
|
|
|
|
<FileTile
|
|
|
|
|
key={claim.claim_id}
|
2017-07-17 08:06:04 +02:00
|
|
|
|
uri={lbryuri.build({
|
|
|
|
|
name: claim.name,
|
|
|
|
|
claimId: claim.claim_id,
|
|
|
|
|
})}
|
2017-09-19 10:16:15 +02:00
|
|
|
|
showLocal={true}
|
2017-06-06 23:19:12 +02:00
|
|
|
|
/>
|
2017-11-24 15:31:05 +01:00
|
|
|
|
))
|
|
|
|
|
) : (
|
|
|
|
|
<span className="empty">{__("No content found.")}</span>
|
|
|
|
|
);
|
2017-05-21 16:42:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-06 23:19:12 +02:00
|
|
|
|
return (
|
2017-07-17 08:06:04 +02:00
|
|
|
|
<div>
|
2017-06-06 23:19:12 +02:00
|
|
|
|
<section className="card">
|
|
|
|
|
<div className="card__inner">
|
2017-11-24 15:31:05 +01:00
|
|
|
|
<div className="card__title-identity">
|
|
|
|
|
<h1>{uri}</h1>
|
|
|
|
|
</div>
|
2017-12-08 21:14:35 +01:00
|
|
|
|
<div className="card__actions">
|
|
|
|
|
<Link
|
|
|
|
|
button="primary"
|
|
|
|
|
label={subscriptionLabel}
|
|
|
|
|
onClick={() =>
|
|
|
|
|
subscriptionHandler({
|
|
|
|
|
channelName: name,
|
|
|
|
|
uri: subscriptionUri,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2017-06-06 23:19:12 +02:00
|
|
|
|
</div>
|
|
|
|
|
<div className="card__content">
|
2017-06-28 22:17:22 +02:00
|
|
|
|
<p className="empty">
|
|
|
|
|
{__(
|
|
|
|
|
"Channel pages are empty for all publishers currently, but will be coming in a future update."
|
|
|
|
|
)}
|
2017-06-06 23:19:12 +02:00
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
<h3 className="card-row__header">{__("Published Content")}</h3>
|
|
|
|
|
{contentList}
|
2017-07-17 08:06:04 +02:00
|
|
|
|
<div />
|
|
|
|
|
{(!fetching || (claimsInChannel && claimsInChannel.length)) &&
|
2017-11-24 15:31:05 +01:00
|
|
|
|
totalPages > 1 && (
|
|
|
|
|
<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)}
|
|
|
|
|
initialPage={parseInt(page - 1)}
|
|
|
|
|
containerClassName="pagination"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2017-07-17 08:06:04 +02:00
|
|
|
|
</div>
|
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;
|