lbry-desktop/src/ui/component/channelTile/view.jsx

89 lines
2.4 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
// @flow
import * as React from 'react';
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';
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() {
const { uri, resolveUri } = this.props;
2017-10-10 01:19:50 +02:00
resolveUri(uri);
2017-10-10 01:19:50 +02:00
}
2018-03-26 23:32:43 +02:00
componentWillReceiveProps(nextProps: Props) {
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) {
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
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
const onClick = () => navigate('/show', { uri, page: 1 });
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"
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>
)}
{subscriptionUri && (
2019-03-19 18:11:28 +01:00
<div className="media__actions">
<SubscribeButton buttonStyle="inverse" uri={subscriptionUri} />
</div>
)}
2017-10-10 01:19:50 +02:00
</div>
</section>
);
}
}
export default ChannelTile;