lbry-desktop/ui/js/component/fileCardStream/view.jsx

115 lines
3.5 KiB
React
Raw Normal View History

2017-04-23 16:01:00 +02:00
import React from 'react';
import lbry from 'lbry.js';
import lbryuri from 'lbryuri.js';
import Link from 'component/link';
import {Thumbnail, TruncatedText,} from 'component/common';
import FilePrice from 'component/filePrice'
import UriIndicator from 'component/channel-indicator';
2017-04-23 16:01:00 +02:00
class FileCardStream extends React.Component {
constructor(props) {
super(props)
this._fileInfoSubscribeId = null
this._isMounted = null
this._metadata = null
this.state = {
2017-04-23 16:01:00 +02:00
showNsfwHelp: false,
isHidden: false,
}
}
componentDidMount() {
2017-04-23 16:01:00 +02:00
this._isMounted = true;
if (this.props.hideOnRemove) {
this._fileInfoSubscribeId = lbry.fileInfoSubscribe(this.props.outpoint, this.onFileInfoUpdate);
}
}
componentWillUnmount() {
2017-04-23 16:01:00 +02:00
if (this._fileInfoSubscribeId) {
lbry.fileInfoUnsubscribe(this.props.outpoint, this._fileInfoSubscribeId);
}
}
onFileInfoUpdate(fileInfo) {
2017-04-23 16:01:00 +02:00
if (!fileInfo && this._isMounted && this.props.hideOnRemove) {
this.setState({
isHidden: true
});
}
}
handleMouseOver() {
2017-04-23 16:01:00 +02:00
this.setState({
hovered: true,
});
}
handleMouseOut() {
2017-04-23 16:01:00 +02:00
this.setState({
hovered: false,
});
}
render() {
2017-04-23 16:01:00 +02:00
if (this.state.isHidden) {
return null;
}
2017-05-02 06:48:16 +02:00
const {
metadata,
isResolvingUri,
navigate,
hidePrice,
claim,
} = this.props
2017-04-23 16:01:00 +02:00
const uri = lbryuri.normalize(this.props.uri);
const isConfirmed = !!metadata;
const title = isConfirmed ? metadata.title : uri;
const obscureNsfw = this.props.obscureNsfw && isConfirmed && metadata.nsfw;
const primaryUrl = 'show=' + uri;
2017-05-02 06:48:16 +02:00
let description = ""
if (isConfirmed) {
description = metadata.description
} else if (isResolvingUri) {
description = "Loading..."
} else {
description = <span className="empty">This file is pending confirmation</span>
}
2017-04-23 16:01:00 +02:00
return (
<section className={ 'card card--small card--link ' + (obscureNsfw ? 'card--obscured ' : '') } onMouseEnter={this.handleMouseOver.bind(this)} onMouseLeave={this.handleMouseOut.bind(this)}>
2017-04-23 16:01:00 +02:00
<div className="card__inner">
2017-05-02 06:48:16 +02:00
<a href="#" onClick={() => navigate(primaryUrl)} className="card__link">
2017-04-23 16:01:00 +02:00
<div className="card__title-identity">
<h5 title={title}><TruncatedText lines={1}>{title}</TruncatedText></h5>
<div className="card__subtitle">
2017-05-02 06:48:16 +02:00
{ !hidePrice ? <span style={{float: "right"}}><FilePrice uri={uri} /></span> : null}
2017-04-23 16:01:00 +02:00
<UriIndicator uri={uri} metadata={metadata} contentType={this.props.contentType}
hasSignature={this.props.hasSignature} signatureIsValid={this.props.signatureIsValid} />
</div>
</div>
2017-05-01 08:26:09 +02:00
{metadata &&
2017-04-23 16:01:00 +02:00
<div className="card__media" style={{ backgroundImage: "url('" + metadata.thumbnail + "')" }}></div>
2017-05-01 08:26:09 +02:00
}
2017-04-23 16:01:00 +02:00
<div className="card__content card__subtext card__subtext--two-lines">
2017-05-02 06:48:16 +02:00
<TruncatedText lines={2}>{description}</TruncatedText>
2017-04-23 16:01:00 +02:00
</div>
</a>
{this.state.showNsfwHelp && this.state.hovered
? <div className='card-overlay'>
<p>
This content is Not Safe For Work.
To view adult content, please change your <Link className="button-text" href="?settings" label="Settings" />.
</p>
</div>
: null}
</div>
</section>
);
}
}
2017-04-23 16:01:00 +02:00
export default FileCardStream