2018-03-08 14:54:26 +11:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
2021-08-12 01:49:10 +10:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
2021-08-12 01:49:10 +10:00
|
|
|
import classNames from 'classnames';
|
2023-05-24 01:15:17 +10:00
|
|
|
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
|
2023-05-09 11:11:56 +10:00
|
|
|
import { Icon } from 'mastodon/components/icon';
|
2017-04-19 23:37:18 +10:00
|
|
|
|
|
|
|
const filename = url => url.split('/').pop().split('#')[0].split('?')[0];
|
|
|
|
|
2017-06-24 03:36:54 +10:00
|
|
|
export default class AttachmentList extends ImmutablePureComponent {
|
2017-04-19 23:37:18 +10:00
|
|
|
|
2017-05-12 22:44:10 +10:00
|
|
|
static propTypes = {
|
2017-05-21 01:31:47 +10:00
|
|
|
media: ImmutablePropTypes.list.isRequired,
|
2018-03-08 14:54:26 +11:00
|
|
|
compact: PropTypes.bool,
|
2017-05-12 22:44:10 +10:00
|
|
|
};
|
|
|
|
|
2017-04-19 23:37:18 +10:00
|
|
|
render () {
|
2018-03-08 14:54:26 +11:00
|
|
|
const { media, compact } = this.props;
|
|
|
|
|
2017-04-19 23:37:18 +10:00
|
|
|
return (
|
2021-08-12 01:49:10 +10:00
|
|
|
<div className={classNames('attachment-list', { compact })}>
|
|
|
|
{!compact && (
|
|
|
|
<div className='attachment-list__icon'>
|
|
|
|
<Icon id='link' />
|
|
|
|
</div>
|
|
|
|
)}
|
2017-04-19 23:37:18 +10:00
|
|
|
|
|
|
|
<ul className='attachment-list__list'>
|
2018-03-08 18:22:04 +11:00
|
|
|
{media.map(attachment => {
|
|
|
|
const displayUrl = attachment.get('remote_url') || attachment.get('url');
|
|
|
|
|
|
|
|
return (
|
|
|
|
<li key={attachment.get('id')}>
|
2021-08-12 01:49:10 +10:00
|
|
|
<a href={displayUrl} target='_blank' rel='noopener noreferrer'>
|
|
|
|
{compact && <Icon id='link' />}
|
|
|
|
{compact && ' ' }
|
|
|
|
{displayUrl ? filename(displayUrl) : <FormattedMessage id='attachments_list.unprocessed' defaultMessage='(unprocessed)' />}
|
|
|
|
</a>
|
2018-03-08 18:22:04 +11:00
|
|
|
</li>
|
|
|
|
);
|
|
|
|
})}
|
2017-04-19 23:37:18 +10:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2017-04-22 04:05:35 +10:00
|
|
|
|
2017-05-12 22:44:10 +10:00
|
|
|
}
|