import React from "react"; import * as icons from "constants/icons"; import lbryuri from "lbryuri.js"; import CardMedia from "component/cardMedia"; import FileActions from "component/fileActions"; import Link from "component/link"; import { TruncatedText } from "component/common.js"; import FilePrice from "component/filePrice"; import NsfwOverlay from "component/nsfwOverlay"; import Icon from "component/icon"; class FileTile extends React.PureComponent { static SHOW_EMPTY_PUBLISH = "publish"; static SHOW_EMPTY_PENDING = "pending"; static defaultProps = { showPrice: true, showLocal: true, }; constructor(props) { super(props); this.state = { showNsfwHelp: false, }; } componentDidMount() { const { isResolvingUri, claim, uri, resolveUri } = this.props; if (!isResolvingUri && !claim && uri) resolveUri(uri); } componentWillReceiveProps(nextProps) { const { isResolvingUri, claim, uri, resolveUri } = this.props; if (!isResolvingUri && claim === undefined && uri) resolveUri(uri); } handleMouseOver() { if ( this.props.obscureNsfw && this.props.metadata && this.props.metadata.nsfw ) { this.setState({ showNsfwHelp: true, }); } } handleMouseOut() { if (this.state.showNsfwHelp) { this.setState({ showNsfwHelp: false, }); } } render() { const { claim, showActions, metadata, isResolvingUri, showEmpty, navigate, showPrice, showLocal, rewardedContentClaimIds, fileInfo, } = this.props; const uri = lbryuri.normalize(this.props.uri); const isClaimed = !!claim; const isClaimable = lbryuri.isClaimable(uri); const title = isClaimed && metadata && metadata.title ? metadata.title : lbryuri.parse(uri).contentName; const thumbnail = metadata && metadata.thumbnail ? metadata.thumbnail : null; const obscureNsfw = this.props.obscureNsfw && metadata && metadata.nsfw; const isRewardContent = claim && rewardedContentClaimIds.includes(claim.claim_id); let onClick = () => navigate("/show", { uri }); let description = ""; if (isClaimed) { description = metadata && metadata.description; } else if (isResolvingUri) { description = __("Loading..."); } else if (showEmpty === FileTile.SHOW_EMPTY_PUBLISH) { onClick = () => navigate("/publish", {}); description = ( {__("This location is unused.")} {" "} {isClaimable && {__("Put something here!")}} ); } else if (showEmpty === FileTile.SHOW_EMPTY_PENDING) { description = ( {__("This file is pending confirmation.")} ); } return ( {showPrice && } {" "} {isRewardContent && } {" "} {showLocal && fileInfo && } {title} {uri} {description && {description} } {this.state.showNsfwHelp && } ); } } export default FileTile;