2017-05-02 20:04:16 -04:00
|
|
|
import React from 'react';
|
2017-04-19 09:37:18 -04:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2018-03-07 22:54:26 -05:00
|
|
|
import PropTypes from 'prop-types';
|
2017-05-30 20:14:26 -04:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
2019-01-31 18:14:05 -05:00
|
|
|
import Icon from 'mastodon/components/icon';
|
2017-04-19 09:37:18 -04:00
|
|
|
|
|
|
|
const filename = url => url.split('/').pop().split('#')[0].split('?')[0];
|
|
|
|
|
2017-06-23 13:36:54 -04:00
|
|
|
export default class AttachmentList extends ImmutablePureComponent {
|
2017-04-19 09:37:18 -04:00
|
|
|
|
2017-05-12 08:44:10 -04:00
|
|
|
static propTypes = {
|
2017-05-20 11:31:47 -04:00
|
|
|
media: ImmutablePropTypes.list.isRequired,
|
2018-03-07 22:54:26 -05:00
|
|
|
compact: PropTypes.bool,
|
2017-05-12 08:44:10 -04:00
|
|
|
};
|
|
|
|
|
2017-04-19 09:37:18 -04:00
|
|
|
render () {
|
2018-03-07 22:54:26 -05:00
|
|
|
const { media, compact } = this.props;
|
|
|
|
|
|
|
|
if (compact) {
|
|
|
|
return (
|
|
|
|
<div className='attachment-list compact'>
|
|
|
|
<ul className='attachment-list__list'>
|
2018-03-08 02:22:04 -05:00
|
|
|
{media.map(attachment => {
|
|
|
|
const displayUrl = attachment.get('remote_url') || attachment.get('url');
|
|
|
|
|
|
|
|
return (
|
|
|
|
<li key={attachment.get('id')}>
|
2019-01-31 18:14:05 -05:00
|
|
|
<a href={displayUrl} target='_blank' rel='noopener'><Icon id='link' /> {filename(displayUrl)}</a>
|
2018-03-08 02:22:04 -05:00
|
|
|
</li>
|
|
|
|
);
|
|
|
|
})}
|
2018-03-07 22:54:26 -05:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2017-04-19 09:37:18 -04:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='attachment-list'>
|
|
|
|
<div className='attachment-list__icon'>
|
2019-01-31 18:14:05 -05:00
|
|
|
<Icon id='link' />
|
2017-04-19 09:37:18 -04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<ul className='attachment-list__list'>
|
2018-03-08 02:22:04 -05:00
|
|
|
{media.map(attachment => {
|
|
|
|
const displayUrl = attachment.get('remote_url') || attachment.get('url');
|
|
|
|
|
|
|
|
return (
|
|
|
|
<li key={attachment.get('id')}>
|
|
|
|
<a href={displayUrl} target='_blank' rel='noopener'>{filename(displayUrl)}</a>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
})}
|
2017-04-19 09:37:18 -04:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2017-04-21 14:05:35 -04:00
|
|
|
|
2017-05-12 08:44:10 -04:00
|
|
|
}
|