1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-30 21:52:08 +02:00
onion/js/components/ascribe_accordion_list/accordion_list_item_piece.js

91 lines
2.7 KiB
JavaScript
Raw Normal View History

'use strict';
import React from 'react';
import { Link } from 'react-router';
import AccordionListItem from './accordion_list_item';
2015-12-02 19:31:50 +01:00
import AccordionListItemThumbnailPlacholder from './accordion_list_item_thumbnail_placeholder';
import { getLangText } from '../../utils/lang_utils';
let AccordionListItemPiece = React.createClass({
propTypes: {
className: React.PropTypes.string,
artistName: React.PropTypes.string,
piece: React.PropTypes.object,
children: React.PropTypes.oneOfType([
React.PropTypes.arrayOf(React.PropTypes.element),
React.PropTypes.element
]),
subsubheading: React.PropTypes.object,
buttons: React.PropTypes.object,
2015-12-02 19:31:50 +01:00
badge: React.PropTypes.object,
thumbnailPlaceholder: React.PropTypes.element
},
getDefaultProps() {
return {
thumbnailPlaceholder: AccordionListItemThumbnailPlacholder
};
},
getLinkData() {
let { piece } = this.props;
if(piece && piece.first_edition) {
return `/editions/${piece.first_edition.bitcoin_id}`;
} else {
return `/pieces/${piece.id}`;
}
},
render() {
2015-12-02 19:31:50 +01:00
const {
artistName,
badge,
buttons,
children,
className,
piece,
subsubheading,
thumbnailPlaceholder: ThumbnailPlaceholder } = this.props;
2015-10-22 10:39:11 +02:00
const { url, url_safe } = piece.thumbnail;
let thumbnail;
// Since we're going to refactor the thumbnail generation anyway at one point,
// for not use the annoying ascribe_spiral.png, we're matching the url against
// this name and replace it with a CSS version of the new logo.
2015-12-02 19:31:50 +01:00
if (url.match(/https:\/\/.*\/media\/thumbnails\/ascribe_spiral.png/)) {
thumbnail = (<ThumbnailPlaceholder />);
2015-10-22 10:39:11 +02:00
} else {
thumbnail = (
<div style={{backgroundImage: 'url("' + url_safe + '")'}}/>
);
}
return (
<AccordionListItem
2015-10-22 10:39:11 +02:00
className={className}
thumbnail={thumbnail}
heading={<h1>{piece.title}</h1>}
subheading={
<h3>
{getLangText('by ')}
2015-10-22 10:39:11 +02:00
{artistName ? artistName : piece.artist_name}
</h3>
}
2015-10-22 10:39:11 +02:00
subsubheading={subsubheading}
buttons={buttons}
badge={badge}
linkData={this.getLinkData()}
>
2015-10-22 10:39:11 +02:00
{children}
</AccordionListItem>
);
}
});
export default AccordionListItemPiece;