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,
|
2018-12-19 06:44:53 +01:00
|
|
|
isSearchResult: boolean,
|
2018-03-26 23:32:43 +02:00
|
|
|
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,
|
2018-12-19 06:44:53 +01:00
|
|
|
buttonStyle: string,
|
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() {
|
2018-12-19 06:44:53 +01:00
|
|
|
const {
|
|
|
|
claim,
|
|
|
|
navigate,
|
|
|
|
isResolvingUri,
|
|
|
|
isSearchResult,
|
|
|
|
totalItems,
|
|
|
|
uri,
|
|
|
|
size,
|
|
|
|
buttonStyle,
|
|
|
|
} = 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
|
|
|
|
2017-12-21 22:08:54 +01:00
|
|
|
const onClick = () => 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', {
|
|
|
|
'media--search-result': isSearchResult,
|
|
|
|
'media--small': size === 'small',
|
|
|
|
'media--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;
|