lbry-desktop/ui/js/component/fileTile/view.jsx
Alex Liebowitz bbfb0fea67 Add <IconSet /> component
This is a presentational component for horizontal banks of icons (and
sometimes other stuff).

Convert <FileCard /> and <FileTile /> to use <IconSet />

Factor out "downloaded/published" icon into its own component

Add Featured Content icon to file tiles

Add alignment style for Featured Content icon

Update CHANGELOG.md

Handle featured content icon adjustment in _icons.scss

Remove IconSet component

Converted back to a presentational span and move positioning styles
into card SCSS

Fix spacing between price and icons in file tiles and cards

Before, it would be missing the space if there was a "local file" icon
but no featured content icon.

Rewrite Icon component to use semantic icons

Now you can pass in a constant that indicates the meaning of the icon
within the interface, e.g. icons.FEATURED instead of "icon-rocket".
Also adds the appropriate title.

All icons should eventually be updated to use this.

Remove IconFeatured and IconLocal in favor of new Icon component

Add space between Featured and Local icons

In the conversion to a generic Icon component, we lost the styles that
added padding on the left for FeaturedIcon and LocalIcon.

Fix how rocket icon position is adjusted

Before, it was using a negative margin, which altered the shape of the
bounding box. Changed to use relative positioning.

Add support for styling LBRY icons

Move style for Featured icon into icons.js

Uses new class name format for LBRY icon styles
2017-09-22 17:48:30 -04:00

149 lines
4.2 KiB
JavaScript

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 = (
<span className="empty">
{__("This location is unused.")} {" "}
{isClaimable &&
<span className="button-text">{__("Put something here!")}</span>}
</span>
);
} else if (showEmpty === FileTile.SHOW_EMPTY_PENDING) {
description = (
<span className="empty">
{__("This file is pending confirmation.")}
</span>
);
}
return (
<section
className={"file-tile card " + (obscureNsfw ? "card--obscured " : "")}
onMouseEnter={this.handleMouseOver.bind(this)}
onMouseLeave={this.handleMouseOut.bind(this)}
>
<div onClick={onClick} className="card__link">
<div className={"card__inner file-tile__row"}>
<CardMedia title={title} thumbnail={thumbnail} />
<div className="file-tile__content">
<div className="card__title-primary">
<span className="card__indicators">
{showPrice && <FilePrice uri={this.props.uri} />}
{" "}
{isRewardContent && <Icon icon={icons.FEATURED} />}
{" "}
{showLocal && fileInfo && <Icon icon={icons.LOCAL} />}
</span>
<div className="meta">{uri}</div>
<h3>
<TruncatedText lines={1}>{title}</TruncatedText>
</h3>
</div>
{description &&
<div className="card__content card__subtext">
<TruncatedText lines={!showActions ? 4 : 2}>
{description}
</TruncatedText>
</div>}
</div>
</div>
</div>
{this.state.showNsfwHelp && <NsfwOverlay />}
</section>
);
}
}
export default FileTile;