attachment_list.jsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import PropTypes from 'prop-types';
  2. import { FormattedMessage } from 'react-intl';
  3. import classNames from 'classnames';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import ImmutablePureComponent from 'react-immutable-pure-component';
  6. import LinkIcon from '@/material-icons/400-24px/link.svg?react';
  7. import { Icon } from 'mastodon/components/icon';
  8. const filename = url => url.split('/').pop().split('#')[0].split('?')[0];
  9. export default class AttachmentList extends ImmutablePureComponent {
  10. static propTypes = {
  11. media: ImmutablePropTypes.list.isRequired,
  12. compact: PropTypes.bool,
  13. };
  14. render () {
  15. const { media, compact } = this.props;
  16. return (
  17. <div className={classNames('attachment-list', { compact })}>
  18. {!compact && (
  19. <div className='attachment-list__icon'>
  20. <Icon id='link' icon={LinkIcon} />
  21. </div>
  22. )}
  23. <ul className='attachment-list__list'>
  24. {media.map(attachment => {
  25. const displayUrl = attachment.get('remote_url') || attachment.get('url');
  26. return (
  27. <li key={attachment.get('id')}>
  28. <a href={displayUrl} target='_blank' rel='noopener noreferrer'>
  29. {compact && <Icon id='link' icon={LinkIcon} />}
  30. {compact && ' ' }
  31. {displayUrl ? filename(displayUrl) : <FormattedMessage id='attachments_list.unprocessed' defaultMessage='(unprocessed)' />}
  32. </a>
  33. </li>
  34. );
  35. })}
  36. </ul>
  37. </div>
  38. );
  39. }
  40. }