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

76 lines
2 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';
2017-10-10 01:19:50 +02:00
2018-03-26 23:32:43 +02:00
/*
This component can probably be combined with FileTile
Currently the only difference is showing the number of files/empty channel
*/
type Props = {
uri: string,
isResolvingUri: boolean,
totalItems: number,
claim: ?{
claim_id: string,
name: string,
},
resolveUri: string => void,
navigate: (string, ?{}) => void,
};
class ChannelTile extends React.PureComponent<Props> {
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, totalItems, uri } = this.props;
2017-10-13 04:08:29 +02:00
let channelName, channelId;
if (claim) {
channelName = claim.name;
channelId = claim.claim_id;
}
2017-10-13 03:37:26 +02:00
const onClick = () => navigate('/show', { uri });
2017-10-10 01:19:50 +02:00
return (
2018-03-26 23:32:43 +02:00
<section className="file-tile card--link" onClick={onClick} role="button">
<CardMedia title={channelName} thumbnail={null} />
<div className="file-tile__info">
{isResolvingUri && <div className="card__title--small">{__('Loading...')}</div>}
{!isResolvingUri && (
<React.Fragment>
<div className="card__title--small card__title--file">
<TruncatedText lines={1}>{channelName || uri}</TruncatedText>
2017-10-13 03:37:26 +02:00
</div>
2018-03-26 23:32:43 +02:00
<div className="card__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>
)}
2017-10-10 01:19:50 +02:00
</div>
</section>
);
}
}
export default ChannelTile;