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';
|
2018-10-22 15:29:27 +02:00
|
|
|
import type { Claim } from 'types/claim';
|
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,
|
2018-10-22 15:29:27 +02:00
|
|
|
claim: ?Claim,
|
2018-03-26 23:32:43 +02:00
|
|
|
resolveUri: string => void,
|
|
|
|
navigate: (string, ?{}) => void,
|
|
|
|
};
|
|
|
|
|
|
|
|
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-02-15 02:52:10 +01:00
|
|
|
const { claim, navigate, isResolvingUri, totalItems, uri, size } = 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;
|
2018-12-13 17:26:51 +01:00
|
|
|
subscriptionUri = `lbry://${claim.permanent_url}`;
|
2017-10-13 04:08:29 +02:00
|
|
|
}
|
2017-10-13 03:37:26 +02:00
|
|
|
|
2019-02-18 18:33:02 +01:00
|
|
|
const onClick = () =>
|
|
|
|
channelName ? navigate('/show', { uri, page: 1 }) : navigate('/show', { uri });
|
2017-10-10 01:19:50 +02:00
|
|
|
|
|
|
|
return (
|
2018-08-24 23:25:18 +02:00
|
|
|
<section
|
|
|
|
onClick={onClick}
|
|
|
|
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} />
|
2018-12-19 06:44:53 +01:00
|
|
|
<div className="media__info">
|
|
|
|
{isResolvingUri && <div className="media__title">{__('Loading...')}</div>}
|
2018-03-26 23:32:43 +02:00
|
|
|
{!isResolvingUri && (
|
|
|
|
<React.Fragment>
|
2018-12-19 06:44:53 +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>
|
2018-12-19 06:44:53 +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>
|
2018-03-26 23:32:43 +02:00
|
|
|
{totalItems} {totalItems === 1 ? 'file' : 'files'}
|
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 && (
|
2018-12-19 06:44:53 +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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ChannelTile;
|