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.

49 lines
1.4 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. const filename = url => url.split('/').pop().split('#')[0].split('?')[0];
  6. export default class AttachmentList extends ImmutablePureComponent {
  7. static propTypes = {
  8. media: ImmutablePropTypes.list.isRequired,
  9. compact: PropTypes.bool,
  10. };
  11. render () {
  12. const { media, compact } = this.props;
  13. if (compact) {
  14. return (
  15. <div className='attachment-list compact'>
  16. <ul className='attachment-list__list'>
  17. {media.map(attachment => (
  18. <li key={attachment.get('id')}>
  19. <a href={attachment.get('remote_url')} target='_blank' rel='noopener'><i className='fa fa-link' /> {filename(attachment.get('remote_url'))}</a>
  20. </li>
  21. ))}
  22. </ul>
  23. </div>
  24. );
  25. }
  26. return (
  27. <div className='attachment-list'>
  28. <div className='attachment-list__icon'>
  29. <i className='fa fa-link' />
  30. </div>
  31. <ul className='attachment-list__list'>
  32. {media.map(attachment => (
  33. <li key={attachment.get('id')}>
  34. <a href={attachment.get('remote_url')} target='_blank' rel='noopener'>{filename(attachment.get('remote_url'))}</a>
  35. </li>
  36. ))}
  37. </ul>
  38. </div>
  39. );
  40. }
  41. }