// @flow import * as React from 'react'; import * as icons from 'constants/icons'; import { normalizeURI, isURIClaimable, parseURI } from 'lbry-redux'; import CardMedia from 'component/cardMedia'; import TruncatedText from 'component/common/truncated-text'; import Icon from 'component/common/icon'; import Button from 'component/button'; import classnames from 'classnames'; type Props = { fullWidth: boolean, // removes the max-width css showUri: boolean, showLocal: boolean, isDownloaded: boolean, uri: string, isResolvingUri: boolean, rewardedContentClaimIds: Array, claim: ?{ name: string, channel_name: string, claim_id: string, }, metadata: {}, resolveUri: string => void, navigate: (string, ?{}) => void, clearPublish: () => void, updatePublishForm: () => void, }; class FileTile extends React.PureComponent { static defaultProps = { showUri: false, showLocal: false, fullWidth: false, }; componentDidMount() { const { isResolvingUri, claim, uri, resolveUri } = this.props; if (!isResolvingUri && !claim && uri) resolveUri(uri); } componentWillReceiveProps(nextProps: Props) { const { isResolvingUri, claim, uri, resolveUri } = nextProps; if (!isResolvingUri && claim === undefined && uri) resolveUri(uri); } render() { const { claim, metadata, isResolvingUri, navigate, rewardedContentClaimIds, showUri, fullWidth, showLocal, isDownloaded, clearPublish, updatePublishForm, } = this.props; const uri = normalizeURI(this.props.uri); const isClaimed = !!claim; const title = isClaimed && metadata && metadata.title ? metadata.title : parseURI(uri).contentName; const thumbnail = metadata && metadata.thumbnail ? metadata.thumbnail : null; const isRewardContent = claim && rewardedContentClaimIds.includes(claim.claim_id); const onClick = () => navigate('/show', { uri }); let name; let channel; if (claim) { ({ name } = claim); channel = claim.channel_name; } return (
{isResolvingUri &&
{__('Loading...')}
} {!isResolvingUri && (
{title || name}
{showUri ? uri : channel || __('Anonymous')} {isRewardContent && } {showLocal && isDownloaded && }
{!name && ( {__('This location is unused.')}{' '}
); } } export default FileTile;