|
|
@ -20,6 +20,16 @@ const getHostname = url => {
|
|
|
|
return parser.hostname;
|
|
|
|
return parser.hostname;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const trim = (text, len) => {
|
|
|
|
|
|
|
|
const cut = text.indexOf(' ', len);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cut === -1) {
|
|
|
|
|
|
|
|
return text;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return text.substring(0, cut) + (text.length > len ? '…' : '');
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default class Card extends React.PureComponent {
|
|
|
|
export default class Card extends React.PureComponent {
|
|
|
|
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
static propTypes = {
|
|
|
@ -33,9 +43,16 @@ export default class Card extends React.PureComponent {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
state = {
|
|
|
|
state = {
|
|
|
|
width: 0,
|
|
|
|
width: 280,
|
|
|
|
|
|
|
|
embedded: false,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
componentWillReceiveProps (nextProps) {
|
|
|
|
|
|
|
|
if (this.props.card !== nextProps.card) {
|
|
|
|
|
|
|
|
this.setState({ embedded: false });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
handlePhotoClick = () => {
|
|
|
|
handlePhotoClick = () => {
|
|
|
|
const { card, onOpenMedia } = this.props;
|
|
|
|
const { card, onOpenMedia } = this.props;
|
|
|
|
|
|
|
|
|
|
|
@ -57,56 +74,14 @@ export default class Card extends React.PureComponent {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
renderLink () {
|
|
|
|
handleEmbedClick = () => {
|
|
|
|
const { card, maxDescription } = this.props;
|
|
|
|
|
|
|
|
const { width } = this.state;
|
|
|
|
|
|
|
|
const horizontal = card.get('width') > card.get('height') && (card.get('width') + 100 >= width);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let image = '';
|
|
|
|
|
|
|
|
let provider = card.get('provider_name');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (card.get('image')) {
|
|
|
|
|
|
|
|
image = (
|
|
|
|
|
|
|
|
<div className='status-card__image'>
|
|
|
|
|
|
|
|
<img src={card.get('image')} alt={card.get('title')} className='status-card__image-image' width={card.get('width')} height={card.get('height')} />
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (provider.length < 1) {
|
|
|
|
|
|
|
|
provider = decodeIDNA(getHostname(card.get('url')));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const className = classnames('status-card', { horizontal });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
<a href={card.get('url')} className={className} target='_blank' rel='noopener' ref={this.setRef}>
|
|
|
|
|
|
|
|
{image}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div className='status-card__content'>
|
|
|
|
|
|
|
|
<strong className='status-card__title' title={card.get('title')}>{card.get('title')}</strong>
|
|
|
|
|
|
|
|
{!horizontal && <p className='status-card__description'>{(card.get('description') || '').substring(0, maxDescription)}</p>}
|
|
|
|
|
|
|
|
<span className='status-card__host'>{provider}</span>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</a>
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
renderPhoto () {
|
|
|
|
|
|
|
|
const { card } = this.props;
|
|
|
|
const { card } = this.props;
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
if (card.get('type') === 'photo') {
|
|
|
|
<img
|
|
|
|
this.handlePhotoClick();
|
|
|
|
className='status-card-photo'
|
|
|
|
} else {
|
|
|
|
onClick={this.handlePhotoClick}
|
|
|
|
this.setState({ embedded: true });
|
|
|
|
role='button'
|
|
|
|
}
|
|
|
|
tabIndex='0'
|
|
|
|
|
|
|
|
src={card.get('embed_url')}
|
|
|
|
|
|
|
|
alt={card.get('title')}
|
|
|
|
|
|
|
|
width={card.get('width')}
|
|
|
|
|
|
|
|
height={card.get('height')}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setRef = c => {
|
|
|
|
setRef = c => {
|
|
|
@ -125,7 +100,7 @@ export default class Card extends React.PureComponent {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
<div
|
|
|
|
ref={this.setRef}
|
|
|
|
ref={this.setRef}
|
|
|
|
className='status-card-video'
|
|
|
|
className='status-card__image status-card-video'
|
|
|
|
dangerouslySetInnerHTML={content}
|
|
|
|
dangerouslySetInnerHTML={content}
|
|
|
|
style={{ height }}
|
|
|
|
style={{ height }}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
@ -133,23 +108,76 @@ export default class Card extends React.PureComponent {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
render () {
|
|
|
|
render () {
|
|
|
|
const { card } = this.props;
|
|
|
|
const { card, maxDescription } = this.props;
|
|
|
|
|
|
|
|
const { width, embedded } = this.state;
|
|
|
|
|
|
|
|
|
|
|
|
if (card === null) {
|
|
|
|
if (card === null) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch(card.get('type')) {
|
|
|
|
const provider = card.get('provider_name').length === 0 ? decodeIDNA(getHostname(card.get('url'))) : card.get('provider_name');
|
|
|
|
case 'link':
|
|
|
|
const horizontal = card.get('width') > card.get('height') && (card.get('width') + 100 >= width) || card.get('type') !== 'link';
|
|
|
|
return this.renderLink();
|
|
|
|
const className = classnames('status-card', { horizontal });
|
|
|
|
case 'photo':
|
|
|
|
const interactive = card.get('type') !== 'link';
|
|
|
|
return this.renderPhoto();
|
|
|
|
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>;
|
|
|
|
case 'video':
|
|
|
|
const ratio = card.get('width') / card.get('height');
|
|
|
|
return this.renderVideo();
|
|
|
|
const height = card.get('width') > card.get('height') ? (width / ratio) : (width * ratio);
|
|
|
|
case 'rich':
|
|
|
|
|
|
|
|
default:
|
|
|
|
const description = (
|
|
|
|
return null;
|
|
|
|
<div className='status-card__content'>
|
|
|
|
|
|
|
|
{title}
|
|
|
|
|
|
|
|
{!horizontal && <p className='status-card__description'>{trim(card.get('description') || '', maxDescription)}</p>}
|
|
|
|
|
|
|
|
<span className='status-card__host'>{provider}</span>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let embed = '';
|
|
|
|
|
|
|
|
let thumbnail = <div style={{ backgroundImage: `url(${card.get('image')})`, width: horizontal ? width : null, height: horizontal ? height : null }} className='status-card__image-image' />;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (interactive) {
|
|
|
|
|
|
|
|
if (embedded) {
|
|
|
|
|
|
|
|
embed = this.renderVideo();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
let iconVariant = 'play';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (card.get('type') === 'photo') {
|
|
|
|
|
|
|
|
iconVariant = 'search-plus';
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
embed = (
|
|
|
|
|
|
|
|
<div className='status-card__image'>
|
|
|
|
|
|
|
|
{thumbnail}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div className='status-card__actions'>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
|
|
|
<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>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
<div className={className} ref={this.setRef}>
|
|
|
|
|
|
|
|
{embed}
|
|
|
|
|
|
|
|
{description}
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
} else if (card.get('image')) {
|
|
|
|
|
|
|
|
embed = (
|
|
|
|
|
|
|
|
<div className='status-card__image'>
|
|
|
|
|
|
|
|
{thumbnail}
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
|
|
<a href={card.get('url')} className={className} target='_blank' rel='noopener' ref={this.setRef}>
|
|
|
|
|
|
|
|
{embed}
|
|
|
|
|
|
|
|
{description}
|
|
|
|
|
|
|
|
</a>
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|