You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.5 KiB

  1. import React from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import PropTypes from 'prop-types';
  4. import ImmutablePureComponent from 'react-immutable-pure-component';
  5. import { FormattedMessage } from 'react-intl';
  6. import classNames from 'classnames';
  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' />
  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' />}
  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. }