PageAttachmentList.jsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import Attachment from './Attachment';
  4. export default class PageAttachmentList extends React.Component {
  5. render() {
  6. if (this.props.attachments <= 0) {
  7. return null;
  8. }
  9. const attachmentList = this.props.attachments.map((attachment, idx) => {
  10. return (
  11. <Attachment
  12. key={`page:attachment:${attachment._id}`}
  13. attachment={attachment}
  14. inUse={this.props.inUse[attachment._id] || false}
  15. onAttachmentDeleteClicked={this.props.onAttachmentDeleteClicked}
  16. isUserLoggedIn={this.props.isUserLoggedIn}
  17. />
  18. );
  19. });
  20. return (
  21. <div>
  22. {(attachmentList.length !== 0)
  23. && <h5><strong>Attachments</strong></h5>
  24. }
  25. <ul className="pl-2">
  26. {attachmentList}
  27. </ul>
  28. </div>
  29. );
  30. }
  31. }
  32. PageAttachmentList.propTypes = {
  33. attachments: PropTypes.arrayOf(PropTypes.object),
  34. inUse: PropTypes.objectOf(PropTypes.bool),
  35. onAttachmentDeleteClicked: PropTypes.func,
  36. isUserLoggedIn: PropTypes.bool,
  37. };
  38. PageAttachmentList.defaultProps = {
  39. attachments: [],
  40. inUse: {},
  41. };