|
|
@ -59,10 +59,12 @@ export default class Card extends React.PureComponent {
|
|
|
|
card: ImmutablePropTypes.map,
|
|
|
|
card: ImmutablePropTypes.map,
|
|
|
|
maxDescription: PropTypes.number,
|
|
|
|
maxDescription: PropTypes.number,
|
|
|
|
onOpenMedia: PropTypes.func.isRequired,
|
|
|
|
onOpenMedia: PropTypes.func.isRequired,
|
|
|
|
|
|
|
|
compact: PropTypes.boolean,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
static defaultProps = {
|
|
|
|
maxDescription: 50,
|
|
|
|
maxDescription: 50,
|
|
|
|
|
|
|
|
compact: false,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
state = {
|
|
|
|
state = {
|
|
|
@ -131,25 +133,25 @@ export default class Card extends React.PureComponent {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
render () {
|
|
|
|
render () {
|
|
|
|
const { card, maxDescription } = this.props;
|
|
|
|
const { card, maxDescription, compact } = this.props;
|
|
|
|
const { width, embedded } = this.state;
|
|
|
|
const { width, embedded } = this.state;
|
|
|
|
|
|
|
|
|
|
|
|
if (card === null) {
|
|
|
|
if (card === null) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const provider = card.get('provider_name').length === 0 ? decodeIDNA(getHostname(card.get('url'))) : card.get('provider_name');
|
|
|
|
const provider = card.get('provider_name').length === 0 ? decodeIDNA(getHostname(card.get('url'))) : card.get('provider_name');
|
|
|
|
const horizontal = card.get('width') > card.get('height') && (card.get('width') + 100 >= width) || card.get('type') !== 'link';
|
|
|
|
const horizontal = (!compact && card.get('width') > card.get('height') && (card.get('width') + 100 >= width)) || card.get('type') !== 'link' || embedded;
|
|
|
|
const className = classnames('status-card', { horizontal });
|
|
|
|
|
|
|
|
const interactive = card.get('type') !== 'link';
|
|
|
|
const interactive = card.get('type') !== 'link';
|
|
|
|
|
|
|
|
const className = classnames('status-card', { horizontal, compact, interactive });
|
|
|
|
const title = interactive ? <a className='status-card__title' href={card.get('url')} title={card.get('title')} rel='noopener' target='_blank'><strong>{card.get('title')}</strong></a> : <strong className='status-card__title' title={card.get('title')}>{card.get('title')}</strong>;
|
|
|
|
const title = interactive ? <a className='status-card__title' href={card.get('url')} title={card.get('title')} rel='noopener' target='_blank'><strong>{card.get('title')}</strong></a> : <strong className='status-card__title' title={card.get('title')}>{card.get('title')}</strong>;
|
|
|
|
const ratio = card.get('width') / card.get('height');
|
|
|
|
const ratio = compact ? 16 / 9 : card.get('width') / card.get('height');
|
|
|
|
const height = card.get('width') > card.get('height') ? (width / ratio) : (width * ratio);
|
|
|
|
const height = card.get('width') > card.get('height') ? (width / ratio) : (width * ratio);
|
|
|
|
|
|
|
|
|
|
|
|
const description = (
|
|
|
|
const description = (
|
|
|
|
<div className='status-card__content'>
|
|
|
|
<div className='status-card__content'>
|
|
|
|
{title}
|
|
|
|
{title}
|
|
|
|
{!horizontal && <p className='status-card__description'>{trim(card.get('description') || '', maxDescription)}</p>}
|
|
|
|
{!(horizontal || compact) && <p className='status-card__description'>{trim(card.get('description') || '', maxDescription)}</p>}
|
|
|
|
<span className='status-card__host'>{provider}</span>
|
|
|
|
<span className='status-card__host'>{provider}</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
);
|
|
|
@ -174,7 +176,7 @@ export default class Card extends React.PureComponent {
|
|
|
|
<div className='status-card__actions'>
|
|
|
|
<div className='status-card__actions'>
|
|
|
|
<div>
|
|
|
|
<div>
|
|
|
|
<button onClick={this.handleEmbedClick}><i className={`fa fa-${iconVariant}`} /></button>
|
|
|
|
<button onClick={this.handleEmbedClick}><i className={`fa fa-${iconVariant}`} /></button>
|
|
|
|
<a href={card.get('url')} target='_blank' rel='noopener'><i className='fa fa-external-link' /></a>
|
|
|
|
{horizontal && <a href={card.get('url')} target='_blank' rel='noopener'><i className='fa fa-external-link' /></a>}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
@ -184,7 +186,7 @@ export default class Card extends React.PureComponent {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div className={className} ref={this.setRef}>
|
|
|
|
<div className={className} ref={this.setRef}>
|
|
|
|
{embed}
|
|
|
|
{embed}
|
|
|
|
{description}
|
|
|
|
{!compact && description}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
);
|
|
|
|
} else if (card.get('image')) {
|
|
|
|
} else if (card.get('image')) {
|
|
|
|