2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
|
|
|
import * as React from 'react';
|
2017-12-21 22:08:54 +01:00
|
|
|
import CardMedia from 'component/cardMedia';
|
2018-03-26 23:32:43 +02:00
|
|
|
import TruncatedText from 'component/common/truncated-text';
|
2018-08-24 23:25:18 +02:00
|
|
|
import classnames from 'classnames';
|
2018-08-27 20:45:50 +02:00
|
|
|
import SubscribeButton from 'component/subscribeButton';
|
2019-04-04 23:05:23 +02:00
|
|
|
import { withRouter } from 'react-router-dom';
|
2019-03-28 17:53:13 +01:00
|
|
|
import { formatLbryUriForWeb } from 'util/uri';
|
2018-03-26 23:32:43 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
uri: string,
|
|
|
|
isResolvingUri: boolean,
|
|
|
|
totalItems: number,
|
2018-08-24 23:25:18 +02:00
|
|
|
size: string,
|
2019-04-24 16:02:08 +02:00
|
|
|
claim: ?ChannelClaim,
|
2018-03-26 23:32:43 +02:00
|
|
|
resolveUri: string => void,
|
2019-04-04 23:05:23 +02:00
|
|
|
history: { push: string => void },
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class ChannelTile extends React.PureComponent<Props> {
|
2018-08-24 23:25:18 +02:00
|
|
|
static defaultProps = {
|
|
|
|
size: 'regular',
|
|
|
|
};
|
|
|
|
|
2017-10-10 01:19:50 +02:00
|
|
|
componentDidMount() {
|
2017-10-12 15:37:24 +02:00
|
|
|
const { uri, resolveUri } = this.props;
|
2017-10-10 01:19:50 +02:00
|
|
|
|
2017-10-12 15:37:24 +02:00
|
|
|
resolveUri(uri);
|
2017-10-10 01:19:50 +02:00
|
|
|
}
|
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
componentWillReceiveProps(nextProps: Props) {
|
2017-10-12 15:37:24 +02:00
|
|
|
const { uri, resolveUri } = this.props;
|
2017-10-10 01:19:50 +02:00
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
if (nextProps.uri !== uri) {
|
2017-10-12 15:37:24 +02:00
|
|
|
resolveUri(uri);
|
2017-10-10 01:19:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2019-04-04 23:05:23 +02:00
|
|
|
const { claim, isResolvingUri, totalItems, uri, size, history } = this.props;
|
2017-10-13 04:08:29 +02:00
|
|
|
|
2018-08-27 20:45:50 +02:00
|
|
|
let channelName;
|
|
|
|
let subscriptionUri;
|
2017-10-13 04:08:29 +02:00
|
|
|
if (claim) {
|
|
|
|
channelName = claim.name;
|
2019-04-24 16:02:08 +02:00
|
|
|
subscriptionUri = claim.permanent_url;
|
2017-10-13 04:08:29 +02:00
|
|
|
}
|
2017-10-13 03:37:26 +02:00
|
|
|
|
2019-04-04 23:05:23 +02:00
|
|
|
const onClick = () => history.push(formatLbryUriForWeb(uri));
|
2017-10-10 01:19:50 +02:00
|
|
|
|
|
|
|
return (
|
2018-08-24 23:25:18 +02:00
|
|
|
<section
|
|
|
|
onClick={onClick}
|
2019-03-19 18:11:28 +01:00
|
|
|
role="button"
|
2018-12-19 06:44:53 +01:00
|
|
|
className={classnames('media-tile card--link', {
|
2019-02-15 02:52:10 +01:00
|
|
|
'media-tile--small': size === 'small',
|
|
|
|
'media-tile--large': size === 'large',
|
2018-08-24 23:25:18 +02:00
|
|
|
})}
|
|
|
|
>
|
2018-03-26 23:32:43 +02:00
|
|
|
<CardMedia title={channelName} thumbnail={null} />
|
2019-03-19 18:11:28 +01:00
|
|
|
<div className="media__info">
|
|
|
|
{isResolvingUri && <div className="media__title">{__('Loading...')}</div>}
|
2018-03-26 23:32:43 +02:00
|
|
|
{!isResolvingUri && (
|
|
|
|
<React.Fragment>
|
2019-03-19 18:11:28 +01:00
|
|
|
<div className="media__title">
|
2018-09-25 01:08:24 +02:00
|
|
|
<TruncatedText text={channelName || uri} lines={1} />
|
2017-10-13 03:37:26 +02:00
|
|
|
</div>
|
2019-03-19 18:11:28 +01:00
|
|
|
<div className="media__subtitle">
|
2017-11-24 15:31:05 +01:00
|
|
|
{totalItems > 0 && (
|
2017-10-13 03:37:26 +02:00
|
|
|
<span>
|
2019-02-18 19:46:51 +01:00
|
|
|
{totalItems} {totalItems === 1 ? 'publish' : 'publishes'}
|
2017-11-24 15:31:05 +01:00
|
|
|
</span>
|
|
|
|
)}
|
2018-03-26 23:32:43 +02:00
|
|
|
{!isResolvingUri && !totalItems && <span>This is an empty channel.</span>}
|
2017-10-13 03:37:26 +02:00
|
|
|
</div>
|
2018-03-26 23:32:43 +02:00
|
|
|
</React.Fragment>
|
|
|
|
)}
|
2018-08-27 20:45:50 +02:00
|
|
|
{subscriptionUri && (
|
2019-03-19 18:11:28 +01:00
|
|
|
<div className="media__actions">
|
|
|
|
<SubscribeButton buttonStyle="inverse" uri={subscriptionUri} />
|
2018-08-27 20:45:50 +02:00
|
|
|
</div>
|
|
|
|
)}
|
2017-10-10 01:19:50 +02:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-04 23:05:23 +02:00
|
|
|
export default withRouter(ChannelTile);
|