lbry-desktop/js/page/show.js

139 lines
3.8 KiB
JavaScript
Raw Normal View History

2016-07-16 04:58:24 +02:00
var formatItemStyle = {
fontSize: '0.95em',
marginTop: '10px',
maxHeight: '220px'
}, formatItemImgStyle = {
maxWidth: '100%',
maxHeight: '100%',
display: 'block',
marginLeft: 'auto',
marginRight: 'auto',
marginTop: '5px',
}, formatHeaderStyle = {
fontWeight: 'bold',
marginBottom: '5px'
}, formatSubheaderStyle = {
marginBottom: '10px',
fontSize: '0.9em'
}, formatItemDescriptionStyle = {
color: '#444',
marginBottom: '5px',
fontSize: '1.2em',
2016-07-16 04:58:24 +02:00
}, formatItemMetadataStyle = {
color: '#444',
marginBottom: '5px',
fontSize: '0.9em',
}, formatItemCostStyle = {
float: 'right'
};
var FormatItem = React.createClass({
propTypes: {
results: React.PropTypes.object,
2016-07-16 04:58:24 +02:00
},
render: function() {
var results = this.props.results;
var name = results.name;
var thumbnail = results.thumbnail;
var title = results.title;
var amount = results.cost_est ? results.cost_est : 0.0;
var description = results.description;
var author = results.author;
var language = results.language;
var license = results.license;
2016-07-17 16:20:37 +02:00
var fileContentType = results['content-type'];
2016-07-16 04:58:24 +02:00
return (
<div className="row-fluid" style={formatItemStyle}>
<div className="span4">
<img src={thumbnail} alt={'Photo for ' + title} style={formatItemImgStyle} />
2016-07-16 04:58:24 +02:00
</div>
<div className="span8">
<h4 style={formatItemMetadataStyle}><b>Address:</b> {name}</h4>
<h4 style={formatItemMetadataStyle}><b>Content-Type:</b> {fileContentType}</h4>
2016-07-16 04:58:24 +02:00
<div style={formatSubheaderStyle}>
<div style={formatItemCostStyle}><CreditAmount amount={amount} isEstimate={true}/></div>
<WatchLink streamName={name} />
2016-07-16 04:58:24 +02:00
&nbsp;&nbsp;&nbsp;
<DownloadLink streamName={name} />
2016-07-16 04:58:24 +02:00
</div>
<p style={formatItemDescriptionStyle}>{description}</p>
2016-07-16 04:58:24 +02:00
<div>
<span style={formatItemMetadataStyle}><b>Author:</b> {author}</span><br />
<span style={formatItemMetadataStyle}><b>Language:</b> {language}</span><br />
<span style={formatItemMetadataStyle}><b>License:</b> {license}</span><br />
2016-07-16 04:58:24 +02:00
</div>
</div>
</div>
);
}
});
var FormatsSection = React.createClass({
propTypes: {
results: React.PropTypes.object,
2016-07-16 04:58:24 +02:00
name: React.PropTypes.string,
},
render: function() {
var name = this.props.name;
var format = this.props.results;
var title = format.title;
2016-07-16 04:58:24 +02:00
if(format == null)
{
return (
<div>
<h1 style={formatHeaderStyle}>Sorry, no results found for "{name}".</h1>
</div>);
}
2016-07-16 04:58:24 +02:00
return (
2016-07-16 07:19:40 +02:00
<div>
<h1 style={formatHeaderStyle}>{title}</h1>
2016-07-16 07:19:40 +02:00
{/* In future, anticipate multiple formats, just a guess at what it could look like
// var formats = this.props.results.formats
2016-07-16 07:19:40 +02:00
// return (<tbody>{formats.map(function(format,i){ */}
<FormatItem results={format}/>
2016-07-16 07:19:40 +02:00
{/* })}</tbody>); */}
</div>);
2016-07-16 04:58:24 +02:00
}
});
var DetailPage = React.createClass({
propTypes: {
name: React.PropTypes.string,
},
getInitialState: function() {
return {
results: null,
searching: true,
};
},
componentWillMount: function() {
lbry.search(this.props.name, (results) => {
this.setState({
results: results[0],
searching: false,
});
});
},
2016-07-16 04:58:24 +02:00
render: function() {
if (this.state.results == null && this.state.searching) {
// Still waiting for metadata
return null;
}
var name = this.props.name;
var metadata = this.state.metadata;
var results = this.state.results;
2016-07-16 04:58:24 +02:00
return (
<main className="page">
<SubPageLogo />
<FormatsSection name={name} results={results}/>
2016-07-16 04:58:24 +02:00
<section>
<Link href="/" label="<< Return" />
</section>
</main>);
}
});