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

101 lines
2.5 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,
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,
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() {
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() {
const {
claim,
navigate,
isResolvingUri,
isSearchResult,
totalItems,
uri,
size,
buttonStyle,
} = 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 });
2017-10-10 01:19:50 +02:00
return (
2018-08-24 23:25:18 +02:00
<section
onClick={onClick}
role="button"
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} />
<div className="media__info">
{isResolvingUri && <div className="media__title">{__('Loading...')}</div>}
2018-03-26 23:32:43 +02:00
{!isResolvingUri && (
<React.Fragment>
<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>
<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>
)}
{subscriptionUri && (
<div className="media__actions">
<SubscribeButton buttonStyle="inverse" uri={subscriptionUri} />
</div>
)}
2017-10-10 01:19:50 +02:00
</div>
</section>
);
}
}
export default ChannelTile;