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